package extends01;
public class wood {
private String name;
private int age;
//构造器有参无参都要写!
public wood(String name, int age) {
this.name = name;
this.age = age;
}
public wood() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package extends01;
public class teacher extends wood{
public teacher(String name, int age) {
//调用父类的有参构造器,初始化继承父类数据
super(name, age);
}
}
package extends01; public class text04 { public static void main(String[] args) { teacher s1 = new teacher("老猪",18); System.out.println(s1.getAge()); System.out.println(s1.getName()); } }