public class test {
public static void main(String[] args) {
Student stu1 =new Student("学炜",24);
stu1.show();
Student stu2=new Undergradute("学炜",24,"硕士");
stu2.show();
}
}
public class Student {
String name;
int age;
public Student() {
super();
}
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public void show(){
System.out.println("学生的名字为:"+this.name+" 学生的年龄为:"+this.age);
}
}
public class Undergradute extends Student{
private String degree;//学位
public Undergradute() {
super();
}
public Undergradute(String name, int age,String degree) {
super(name, age);
this.degree=degree;
}
public void show(){
System.out.println("学生的名字为:"+this.name+" 学生的年龄为:"+this.age+" 学生的专业为:"+this.degree);
}
}