这么简单啊。
public class Student {
private String name;
private int age;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void show() {
System.out.println(String.format("name=%s \tage=%s ", name, age));
}
}
public class Undergraduate extends Student {
private String degree;
public Undergraduate() {
}
public Undergraduate(String degree, String name, int age) {
super(name, age);
this.degree = degree;
}
@Override
public void show() {
System.out.println(String.format("degree=%s \tname=%s \tage=%s",
degree, super.getName(), super.getAge()));
}
}
public class StuTest {
public static void main(String[] args) {
//基类
Student stu = new Student("李四",22);
stu.show();
//子类
Student degree = new Undergraduate("大学",stu.getName(),stu.getAge());
degree.show();
}
}
可以写的 写就see my name, find me
老师,我不会啦!!我是来打酱油额!!