标题:这其中的this代表什么?整个代码的意思我很糊涂。
取消只看楼主
dlwangrenjie
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-3-23
结帖率:0
已结贴  问题点数:20 回复次数:1 
这其中的this代表什么?整个代码的意思我很糊涂。
import java.util.*;
/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@
 * @version  1.0
 */
public class Canvas
{
    //同时在画布上绘制多个形状
    public void drawAll(List<? extends Shape> shapes)
    {
        for (Shape s : shapes)
        {
            s.draw(this);
        }
    }
    public static void main(String[] args)
    {
        List<Circle> circleList = new ArrayList<Circle>();
        circleList.add(new Circle());
        Canvas c = new Canvas();
        c.drawAll(circleList);
    }
}


/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@
 * @version  1.0
 */
//定义一个抽象类Shape
public abstract class Shape
{
    public abstract void draw(Canvas c);
}
 


/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@
 * @version  1.0
 */
//定义Shape的子类Circle
public class Circle extends Shape
{
    //实现画图方法,以打印字符串来模拟画图方法实现
    public void draw(Canvas c)
    {
        System.out.println("在画布" + c + "画一个圆");
    }
}
搜索更多相关主题的帖子: void class Copyright copyright version 
2012-03-23 22:59
dlwangrenjie
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-3-23
得分:0 
circleList.add(new Circle());自动调用public void draw(Canvas c)并把括号里的实参Canvas c传入方法里面吗?Canvas c依我看应该是形参。所以我认为circleList.add(new Circle());这句并没有传入实参。我说的对吗?
 
2012-03-25 15:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-364155-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.365494 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved