Java-调用抽象类中指定参数的构造方法

时间:2021-05-09 22:21:06

abstract class person
{
 private String name;
 private int age;
 public person(String name,int age)
 {
         this.setage(age);
         this.setname(name);
 }
 public void setage(int age)
 {
  this.age=age;
 }
 public int getage()
 {
  return this.age;
 }
 public void setname(String name)
 {
  this.name=name;
 }
 public String getname()
 {
  return this.name;
 }
 public abstract String getinfo();
}
class student extends person
{
 private String school;
 public student(String name,int age,String school)
 {
  super(name,age);
  this.setschool(school);
 }
 public void setschool(String school)
 {
  this.school=school;
 }
 public String getschool()
 {
  return this.school;
 }
 public String getinfo()
 {
  return "姓名:"+super.getname()+"\t年龄:"+super.getage()+"\t学校:"+this.getschool();
 }
}
public class test33 {
 public static void main(String args[])
 {
  student stu=new student("Aaron",21,"****学院");
  System.out.print(stu.getinfo());
 }

}