package com.ufe01;
public class Student1 extends People{
//如果父类的方法不满足子类的需求,
//子类可以写一个一摸一样的方法在自己的类体中,这样就实现了方法重写
public void eat(){
System.out.println("学生爱吃米饭");
}
}
package com.ufe01;
public class Teacher extends People{
public void sleep(){
System.out.println("老师爱睡觉");
}
}
package com.ufe01;
public class Test {
public static void main(String[] args) {
//创建学生对象
Student1 s=new Student1();
s.eat();
s.sleep();
System.out.println("---------------------------");
//创建一个老师对象
Teacher t=new Teacher();
t.eat();
t.sleep();
}
}