Green Ho
Green Ho

Reputation: 901

Java: Alternative to Multiple inheritance

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!

Upvotes: 0

Views: 1418

Answers (1)

ZhongYu
ZhongYu

Reputation: 19682

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.

Upvotes: 1

Related Questions