`
Spirit_eye
  • 浏览: 18166 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

多态与内部类(转载)

阅读更多
程序:
package basic;

public class polymorphism {
class Glyph {
Glyph() {
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph() before draw()");
}
void draw(){
System.out.println("dddfee");
}
}



class RoundGlyph extends Glyph {
private int xx = 1;

RoundGlyph(int r) {
xx = r;
System.out.println("RoundGlyph.draw() " + xx);
}

void draw() {
System.out.println("RoundGlyph.draw() " + xx);
}
}

public static void main(String[] args) {
polymorphism ply = new polymorphism();
ply.new RoundGlyph(5);
}
}

运行结果:
Glyph() before draw()
RoundGlyph.draw() 0
Glyph() before draw()
RoundGlyph.draw() 5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics