Java中用多个子类实现父类方法
我有一个类(我们称之为 A
),它由几个子类(B
、C
、D
扩展) > 等)。
在每个子类中,我希望可以从父类 A
的实例中访问这些特定方法。
我尝试将 A
声明为抽象类,并将其中的每个子类方法声明为抽象类。然后我在自己的类中实现了这些方法,但似乎每个子类都必须实现父类的每个方法。但是,我不能这样做。
对于这个问题你有什么想法吗?
I have a class (let's call it A
) that is extended by several children class (B
, C
, D
, etc.).
In each child class, there are specific methods that I'd like to be accessible from an instantiation of the parent class A
.
I tried to declare A
as an abstract class, and to declare each child class methods inside as abstract. Then I implemented these methods in their own class but it seems that each child class must implement every method of the parent class. However, I can't do this.
Would you have an idea for this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在每个子类中,我希望可以从父类 A 的实例化中访问特定的方法。
这不是继承的重点。即使你能做到这一点,也表明你的设计被破坏了。
In each children class, there are specific methods that I'd like to be accessible from an instantiation of the parent class A.
That's not the point of inheritance. Even if you could do this, it shows that your design is broken.