开发者

Implementing parent class methods with several children class in Java

开发者 https://www.devze.com 2023-01-29 08:30 出处:网络
I have a class (let\'s call it A) that is extended by several children class (B, C, D, etc.). In eac开发者_JS百科h child class, there are specific methods that I\'d like to be accessible from an ins

I have a class (let's call it A) that is extended by several children class (B, C, D, etc.).

In eac开发者_JS百科h 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消