问题
I have a class A that has to extend class B and C which are both provided by 3rd party and I don't have a control of them. Since Java doesn't support multiple inheritance. Using interface wouldn't help in my case since I do want to inherit the base classes' implementation and I don't want to copy their code over to my class, or I'll need to be aware of all their coming changes.
What would be the best way to accomplish this need?
All suggestion will be much appreciated!
回答1:
class A
class B2 extends B
inherit B's stuff
class C2 extends C
inherit C's stuff
B2 b2 = new B2();
C2 c2 = new C2();
// or use anonymous classes
A has access to everything in B2 and C2,
therefore A has access to B and C's inheritable assets.
来源:https://stackoverflow.com/questions/17226364/java-alternative-to-multiple-inheritance