Implementing parent class methods with several children class in Java

一个人想着一个人 提交于 2019-12-20 07:33:43

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4394129/implementing-parent-class-methods-with-several-children-class-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!