look。
下面这段代码:
package test;
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 p163 extends Glyph{
private int radius=1;
p163(int r){
radius=r;
System.out.println("RoundGlyph.RoundGlyph(),radius="+radius);
}
void draw(){
System.out.println("RoundGlyph.draw(),radius="+radius);
}
public static void main(String args[]){
new p163(5);
}
}
在子类初始化的过程中,先调用父类的构造器。在调用父类的构造函数的过程中,调用draw函数。应该说明的是,这里的draw函数其实是调用的子类中的draw函数。因为,这里的draw函数其实是重载了父类的draw函数。