0

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?

2
  • Can you give any more detail about what you are trying to do? What code have you written so far? Do B, C and D all implement the same abstract method or do they implement different ones? Dec 9, 2010 at 1:51
  • Yes, the thing is that they implement different ones. Basically, the abstract class A contains the declaration of abstract methods m1, m2, m3, m4, m5... Class B implements m1, m2; class C implements m3, class D implements m4, m5. Hope it's clear enough. Thx!
    – Nicolas P.
    Dec 9, 2010 at 3:23

1 Answer 1

2

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.

2
  • Oh. I'm not an expert in Java, I didn't know it wasn't possible. Thanks for the answer.
    – Nicolas P.
    Dec 9, 2010 at 3:22
  • I'm not saying it's not possible, I'm saying don't do it.
    – Falmarri
    Dec 9, 2010 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.