class L805
{
public static void main(String[] args)
{
Son s1 = new Son(); //1
System.out.println(s1.getName() + "..." + s1.getAge());//9
System.out.println("--------------------"); //10
Son s2 = new Son("张三",23); //11
System.out.println(s2.getName() + "..." + s2.getAge());//16
}
}
class Father {
private String name;
private int age;
//public Father()
//{
// System.out.println("Father 空参构造");
//}
public Father(String name,int age) //6 //14
{
this.name = name;
this.age = age;
System.out.println("Father 有参构造");
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
}
class Son extends Father
{
public Son() //2
{
this("王五",25); //3
//super("李四",24);
System.out.println("Son 空参构造"); //8
}
public Son(String name,int age) //4 //12
{
super(name,age); //5 //13
System.out.println("Son 有参构造"); //7 //15
}
} |
|