标题:[讨论]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



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




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

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