package Student; public class Student {     protected String name;     protected int age;          public Student(String name, int age){         this.name = name;         this.age = age;     }          public void show() {         System.out.println("姓名:" + this.name + ";" + "年龄:" + this.age);     }          public static void main(String[] args){         Student student = new Student("小红", 19);         Undergraduate unstudent = new Undergraduate("小明", 18, "计算机");         student.show();         unstudent.show();     } } class Undergraduate extends Student{     private String degree;          public Undergraduate(String name, int age, String degree){         //调用父类构造函数         super(name, age);         this.degree = degree;     }     //重写父类show方法     @Override     public void show() {         System.out.println("姓名:" + this.name + ";" + "年龄:" + this.age + ";" + "专业:" + this.degree);     } }
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务