package main;
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;
public RoundGlyph(int r) {
radius = r;
System.out.println("RoundGlyph");
}
void draw() {
System.out.println("RoundGlyph.draw()");
}
}
public class test {
public static void main(String[] args) {
new RoundGlyph(4);
}
}
输出为:
Glyph() before draw()
RoundGlyph.draw()
Glyph() after draw()
RoundGlyph
为什么基类构造器调用的draw()方法是RoundGlyph的,难道在基类构造器中的调用已经发生了导出类draw的重写了吗?