public class Test {
public static void main(String[] args) {
Student student = new Student("肖捷", 28);
student.show();
Undergraduate undergraduate = new Undergraduate("***", 29, "经济学");
undergraduate.show();
}
}
class Student {
private String name;
private int age;
Student (String name, int age){
this.name = name;
this.age = age;
}
protected void show() {
System.out.println("学生名字是:" + name);
System.out.println("该学生的年龄是:" + age);
}
}
class Undergraduate extends Student{
private String degree;
Undergraduate(String name, int age, String degree) {
super(name, age);
this.degree = degree;
}
protected void show() {
super.show();
System.out.println("该学生的学位是:" + degree);
}
}