0

我有一个 A 类,它必须扩展 B 类和 C 类,它们都是由第 3 方提供的,我无法控制它们。由于Java不支持多重继承。在我的情况下,使用接口没有帮助,因为我确实想继承基类的实现并且我不想将它们的代码复制到我的类中,或者我需要了解它们即将发生的所有变化。

满足这种需求的最佳方法是什么?

所有建议将不胜感激!

4

1 回答 1

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.
于 2013-06-21T01:31:30.180 回答