package pakage;
public class DynamicBindingDemo {
public static void main(String args[]) {
m(new GraduateStudent());
m(new Student());
m(new Person());
m(new Object());
}
public static void m(Object x) {//Object类型可以用任何类型访问它
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";
}
}
}
柳太爷
相关分类