java教师和学生类的继承代码_java-继承实现学生类和老师类案例

  • Post author:
  • Post category:java


java-继承实现学生类和老师类案例::

定义一个父类:

package day08;

public class PersonDemo {

private String name;

private int age;

public PersonDemo(){

}

public PersonDemo(String name,int age){

this.name=name;

this.age=age;

}

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;

}

}子类:student

package day08;

public class StudentDemo extends PersonDemo{

public StudentDemo(){

}

public StudentDemo(String name,int age){

super(name,age);//调用父类的有参构造方法

}

}

<



版权声明:本文为weixin_39580748原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。