- class TestExtends {
- public static void main(String[] args){
- Student s = new Student();
- s.eat();
- }
- }
- class Person{
- private String name;
- private int age;
- 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();
- }
- public void study(){
- System.out.println("学习");
- }
- }
- class Teacher {
- public Teacher(){}
- public Teacher(String name,int age) {
- super();
- }
- public void teach(){
- System.out.println("教学");
- }
- }
复制代码
|
|