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

相关推荐

AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
03-16 13:56
湖南大学 C++
牛客872108596号:到现在没消息是挂了吗查看图片
点赞 评论 收藏
分享
牛客网
牛客企业服务