【发布时间】:2011-07-09 10:05:15
【问题描述】:
是否有可能一个类有一个只能由它的对象调用并为子类对象隐藏的方法?例如:
class ClassOne {
... // attributes
public void doSomething() { ... }
}
class ClassTwo extends ClassOne {
... // attributes and methods
}
ClassOne c1 = new ClassOne();
c1.doSomething(); // ok to call
ClassTwo c2 = new ClassTwo();
c2.doSomething(); // forbidden
我知道从继承的角度来看这似乎很奇怪,但这可能吗?
PS:这个问题的目的只是为了进一步了解 OO 编程的继承。
【问题讨论】:
标签: java class inheritance methods