Answer the question
In order to leave comments, you need to log in
How in Java to break a class into three smaller ones so that the inheritance chain is not lost?
There is a class B. It is necessary to split it into classes H and G, without losing the inheritance chain, so that the methods of the new classes are also available to the heirs of class B, and the methods of class A and B are available to classes H and G.
Answer the question
In order to leave comments, you need to log in
- Drag and drop the logic you need into the H and G class (without inheritance)
- In the 'B' class, make fields for the H and G instances (think through the constructor, or initialize there.
- 'B' inherit from A. Optional somehow give descendants access to H and G (via B methods or directly to fields)
Java does not support multiple inheritance, but you can take out common interfaces and inherit from them.
What kind of account?
https://javarush.ru/groups/posts/731-mnozhestvenno...
Java does not support multiple inheritance.
Adult developers use the Composition pattern.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question