How to create a class that “extends” two existing concrete classes

后端 未结 8 2031
悲哀的现实
悲哀的现实 2020-12-19 20:36

I very well know that it can be done with the help of interfaces and i have done it many times. But this time my situation is quite difference. I have class A ,

8条回答
  •  [愿得一人]
    2020-12-19 21:19

    You may try create class C that will contain one instance of class A and one of class B and their methods (create methods with same names that will just call methods from A and B), it's called Composition - another method in opposite to inheritance. Of course that's in case if you don't need instanceof to work with that C class.

提交回复
热议问题