class Demo12 {
public static void main(String[] args) {
Son s = new Son();
Son s2 = new Son("张三",23);
}
}
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() {
System.out.prntln("Son 空参构造"); //子类空参构造
}
public Son(String name,int age) {
System.out.print("Son 有参构造"); //子类有参构造
}
}
我要抓狂了,哪里出错了 |
|