class Student { String name; int age; public Student(String co_name,int co_age){ name = co_name; age = co_age;   }   public void show(){ System.out.println("我的名字是"+name+":"+age+"years old!");   } } class Undergradute extends Student{ String degree; public Undergradute(String co_name,int co_age,String getDegree){ super(co_name,co_age);   degree = getDegree; } public void show(){ System.out.println("我是"+name+",今年"+age+"岁,学位是"+degree); } } class Test{ public static void main(String[] args){ Student stu1 = new Student("明仔",23);   Student stu2 = new Student("红红",22);   Student stu3 = new Undergradute("继伟",30,"本科");   Student stu4 = new Undergradute("小霞",28,"研究生");   stu1.show();   stu2.show(); stu3.show(); stu4.show(); } }
点赞 评论

相关推荐

牛客网
牛客企业服务