构造器和多态
构造器的调用顺序(P159)
构造器内部的多态方法的行为(P162-163)
public class Glyph {
void draw(){
System.out.println("Glyph draw");
}
Glyph(){
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph() after draw()");
}
}public 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);
}
}总结(P164)
Last updated