【发布时间】:2011-02-11 16:07:16
【问题描述】:
如果我有一个基类
Base thing = null;
其中有一个子类
class Subclass extends Base
我煽动它
thing = new Subclass
我将如何调用专门在子类中但不在 Base 中的方法?
前任。
Base 只有 method()
Subclass 有 method() 和 specialMethod()
specialMethod() 方法是我要调用的方法。
【问题讨论】:
-
这通常是个坏主意。如果您知道该对象是 Subclass 类型,那么就这样引用它,您就没有问题。如果该方法确实属于 Base - 将其放在 Base 中。
标签: java