今天课上老师讲了一个例子,对执行流程还不是很清楚,特来请各位大神解惑!题目如下:
class Extends {
public static void main(String[] args) {
Son s1 = new Son();
System.out.println(s1.getName() + "..." + s1.getAge());
System.out.println("--------------------");
Son s2 = new Son("张三",23);
System.out.println(s2.getName() + "..." + s2.getAge());
}
}
class Father {
private String name;
private int age;
public Father() {
System.out.println("Father 空参构造");
}
public Father(String name,int age) {
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() {
this("王五",25);
System.out.println("Son 空参构造");
}
public Son(String name,int age) {
super(name,age);
System.out.println("Son 有参构造");
}
}
请问这个程序是怎么执行的,依次会输出什么!
|
|