class Student{          private String name;     private int age;     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public int getAge() {         return age;     }     public void setAge(int age) {         this.age = age;     }     /**      * @param name      * @param age      */     public Student(String name, int age) {         super();         this.name = name;         this.age = age;     }          public Student() {         // TODO Auto-generated constructor stub     }          public void show() {         System.out.println("Student [name=" + name + ", age=" + age + "]");     } } class Undergraduate extends Student{          private String degree;     public String getDegree() {         return degree;     }     public void setDegree(String degree) {         this.degree = degree;     }     /**      * @param name      * @param age      * @param degree      */     public Undergraduate(String name, int age, String degree) {         super(name, age);         this.degree = degree;     }     @Override     public void show() {         System.out.println("Undergraduate [ degree=" + degree + "]");     } } public class TestStudent3 {     public static void main(String[] args) {         Student student1 = new Student("张三", 12);         Student student2 = new Student("李四", 13);         student1.show();         student2.show();         Undergraduate undergraduate = new Undergraduate("王五", 20, "硕士");         undergraduate.show();     } }
点赞 评论

相关推荐

循此苦旅:月初笔试全a,没面试!
点赞 评论 收藏
分享
香梨想要offer:人手一个muduo
点赞 评论 收藏
分享
牛客网
牛客企业服务