多态 传值的一个问题

hh7551035 hh7551035 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package poly;



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

class RoundGlyph extends Glyph{
private int radius = 1;
public RoundGlyph(int i) {
// TODO Auto-generated constructor stub
radius = i;
System.out.println("RoundGlyph.RoundGlyph().radius = "+radius);
}
void draw(){
System.out.println("RoundGlyph.draw().radius = "+radius); //这里为什么输出的是0,不太懂。怎么会是0呢
}
}
public class PolyCjonstructors {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new RoundGlyph(5);

}

}
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
hh7551035
Java SE 62,620 成员 307,251 内容