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);
}
@Override
void draw() {
System.out.println("roundGlyph.draw:" + radius);
}
}
public class PolyConstructors {
public static void main(String[] args) {
new RoundGlyph(3);
}
}
the output is :
glyph() before draw
**roundGlyph.draw:0**
glyph() after draw
roundGlyph.RoundGlyph:3
I am confused about the second result,why the code draw()
in the parent class constructor,actually invoke the child draw method other than parent draw method?