class Father{
private int age;
public Father(){
System.out.println("hello world is Father.");
}
public Father(int age){
this.age=age;
System.out.println("Father's age is "+age);
}
}
class Son extends Father{
private int age;
public Son(int age){
this.age=age;
System.out.println("Son's age is "+age);
}
public Son(){
System.out.println("Son's hello world");
}
}
class TestFun{
public static void main(String args[]){
Son s=new Son(20);
Son s2=new Son();
}
}
程序执行的结果:
hello world is Father.
Son's age is 20
hello world is Father.
Son's hello world