【发布时间】:2015-04-26 13:26:43
【问题描述】:
public class Base {
public String className() {
return "Base";
}
}
public class Derived extends Base {
@Override
public String className() {
return “Derived”;
}
public void testCalls() {
Base base = (Base)this;
out.println("Through this: " + this.className());
out.println("Through base: " + base.className());
out.println("Through super: " + super.className());
}
}
this 和 super 哪来的?还有为什么是 out.println 而不是 System.out.println?
【问题讨论】:
-
多读几页你引用这个例子的书。我相信他们会解释每一点。
-
请正确缩进您的代码。
标签: java polymorphism base derived-class println