| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 687 人关注过本帖
标题:[讨论]Thinking in Java 3中的一个程序
取消只看楼主 加入收藏
littlec
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-10-10
收藏
 问题点数:0 回复次数:0 
[讨论]Thinking in Java 3中的一个程序

class Glyph {
void draw(){System.out.println("Glyph.draw()");};
Glyph() {
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph() after draw()");
}
}

class RoundGlyph extends Glyph {
private int radius = 1;
RoundGlyph(int r) {
radius = r;
System.out.println(
"RoundGlyph.RoundGlyph(), radius = " + radius);
}
void draw() {
System.out.println(
"RoundGlyph.draw(), radius = " + radius);
}
}

public class PolyConstructors {
public static void main(String[] args) {
new RoundGlyph(5);
}
} ///:~
程序运行结果是:

Glyph() before draw()
RoundGlyph.draw(), radius = 0
Glyph() after draw()
RoundGlyph.RoundGlyph(), radius = 5
第二行调用了派生类的draw()函数,为什么?

搜索更多相关主题的帖子: draw Thinking Java radius Glyph 
2007-10-17 22:57
快速回复:[讨论]Thinking in Java 3中的一个程序
数据加载中...
 
   



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

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