public Person(){} //无参构造函数
public Person(String name,int age){ //有参构造函数
this.name=name;
this.age=age;
}
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;
}
public void eat(){ //吃饭函数
System.out.println("吃饭");
}
}
class Student extends Person{ //定义定义学生类
public Student(){} //定义无参构造函数
public Student(String name,int age){
super(name,age);
}
public void learn(){
System.out.println("学习");
}
}
class Teacher extends Person { //定义老师类
public Teacher(){}
public Teacher(String name,int age){ //定义有参构造函数
super(name,age);
}
public void teach(){ //老师类功能方法
System.out.println("老师教学");
}
}