我是Java的新手,只是试图让基础知识失败。我在我的抽象类中抛出了我的主类对象的代码,我不确定要改变什么。
public class Test {
public static void main(String[] args) {
m(new GraduateStudent());
m(new Student());
m(new Person());
m(new Object());
}
public static void m(Student x) {
System.out.println(x.toString());
}
}
class GraduateStudent extends Student {
}
class Student extends Person {
public String toString() {
return "Student";
}
}
class Person extends Object {
public String toString() {
return "Person";
}
}
答案 0 :(得分:1)
简单改变
public static void m(Student x) {
System.out.println(x.toString());
}
到
public static void m(Object x) {
System.out.println(x.toString());
}
因为所有子课程都可以投递到父母,所以父母不能被投入到孩子身上