package student; class Student{     //父类属性访问权限设置为protected,可供子类访问     protected String name;     protected int age;     public Student(String name,int age)     {         this.name=name;         this.age=age;     }     public void show()     {         System.out.print("姓名:"+this.name+" ");         System.out.print("年龄:"+this.age);     } } class Undergraduate extends Student{          private String degree;          public Undergraduate(String name,int age,String degree)     {         super(name,age);//使用super()函数来调用父类相应的构造函数;         this.degree=degree;     }     public void show()     {         System.out.print("姓名:"+this.name+" ");         System.out.print("年龄:"+this.age+" ");         System.out.print("学位:"+this.degree);     } }  public class StudentTest {          public static void main(String[] args)     {         System.out.println("===学生类测试===");         Student s=new Student("李明",22);         s.show();         System.out.println();         System.out.println("===本科生类测试===");         s=new Undergraduate("张三",23,"学士学位");         s.show();     } }
点赞 评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务