/** * 设计一个学生类Student和它的子类Undergradute,要求如下: * 1.Student类有name(姓名)和age(年龄),一个包含两个参数的构造方法, * 用于给name和age属性赋值,一个show()方法dayinStudent的属性信息。 * @author FeiEr * */ public class Student { String name; int age; public Student(String name,int age) { this.name = name; this.age = age; } public void show() { System.out.println("我是"+name+","+"今年"+age+"岁!"); } }/** * 2.本科生类Undergraduate增加一个degree(学位)属性。有一个包含三个 * 参数的构造方法,前两个参数用于给继承的name和age赋值,第三个参数给degree专业赋值, * 一个show()方法打印Undergrate的属性信息。 * @author FeiEr * */ public class Undergraduate extends Student { private String degree; public Undergraduate(String name, int age, String degree) { super(name, age); this.degree = degree; } public void show() { System.out.println("我是"+name+","+"今年"+age+"岁"+","+degree+"毕业!"); } }/** * 3.在测试类中创建Student对象和Undergraduate的属性信息。 * @author FeiEr * */ public class Test001 { public static void main(String[] args) { Student student = new Student("王飞",24); Undergraduate undergraduate = new Undergraduate("王剑",23,"硕士"); student.show(); undergraduate.show(); } }