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);     } }
点赞 评论

相关推荐

不愿透露姓名的神秘牛友
07-01 11:27
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务