类名是:Undergraduate,里边的代码在下边
class Student{
String name;
int age;
public Student(String name,int age){
this.name = name;
this.age = age;
}
public void show(){
System.out.println("Student类,学生信息,姓名:"+name+",年龄:"+age);
}
}
public class Undergraduate extends Student{
private String degree;
public Undergraduate(String name,int age,String degree){
super(name,age);
this.name = name;
this.age = age;
this.degree = degree;
}
public void show(){
System.out.println("Undergraduate类,学生信息,姓名:"+name+",年龄:"+age+",学位:"+degree);
}
public static void main(String[] args) {
Student s = new Student("张三",20);
s.show();
Undergraduate u = new Undergraduate("李四",23,"本科");
u.show();
// 多态
Student su = new Undergraduate("王五",21,"专科");
su.show();
}
}