本文主要是介绍day6 test06,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package day6;
//类的继承是为了实现代码的复用,如果有多个类具有相同的方法,我们应该尽量抽取出父类class Person2
{String name;int age;public void eat(){System.out.println(this.name + " is eating@!!!");}
}class Student extends Person2
{String stuId;public void study(){System.out.println("studying!!!");}
}class Teacher extends Person2
{String employeeId;public void eat(){System.out.println("chou yi gen");super.eat();System.out.println("chou yi gen");}public void teach(){//super.eat();System.out.println("teaching@!!!");}
}public class test06 {public static void main(String args[]){Teacher t = new Teacher();t.name = "xwh";t.age = 32;t.eat();t.teach();}
}
这篇关于day6 test06的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!