java 设计一个学生类Student和它的一个字类Undergraduate,要求如下:

2020-06-21 教育 563阅读
这么简单啊。
public class Student {
private String name;
private int age;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void show() {
System.out.println(String.format("name=%s \tage=%s ", name, age));
}
}
public class Undergraduate extends Student {
private String degree;
public Undergraduate() {
}
public Undergraduate(String degree, String name, int age) {
super(name, age);
this.degree = degree;
}
@Override
public void show() {
System.out.println(String.format("degree=%s \tname=%s \tage=%s",
degree, super.getName(), super.getAge()));
}
}
public class StuTest {
public static void main(String[] args) {

//基类
Student stu = new Student("李四",22);
stu.show();
//子类
Student degree = new Undergraduate("大学",stu.getName(),stu.getAge());
degree.show();

}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com