日期:2014-05-20 浏览次数:20690 次
public class ClassB extends ClassA{
public static void main(String[] args) {
new ClassB();
}
public ClassB() {
}
public void action(){
System.out.println("重写");
}
}
class ClassA{
public ClassA() {
action();
}
public void action(){
System.out.println("父类");
}
}
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="+radius);
}
void draw() {
System.out.println("RoundGlyph.draw(),radius="+radius);
}
}
public class PolyConstructors {
public static void main(String args[]) {
new RoundGlyph(5);
}
}
/*
Output:
Glyph() before draw()
RoundGlyph.draw(),radius=0
Glyph() after draw()
RoundGlyph. RoundGlyph(),radius=5
*/