public class Undergraduate extends Student { private String degree; public Undergraduate(String name, int age, String degree) { super(name, age); this.degree = degree;
} @Override public void show() { super.show();
System.out.println("学位:" + degree);
}
}
public class Student { private String name; private int age; public Student(String name, int age) { this.name = name; this.age = age;
} public void show(){
System.out.println("姓名:" + name + "\n年龄:" + age);
}
}
public class TestStudent { public static void main(String[] args) {
Student s1 = new Student("yhviews", 20);
Undergraduate u1 = new Undergraduate("zeal", 22, "本科");
s1.show();
u1.show();
}
}