public class Main {
    interface A {
        int a();
    }

    static class B implements A {
        @Override
        public int a() {
            return 1;
        }
    }

    static class C implements A {
        @Override
        public int a() {
            return 2;
        }
    }

    static class D1 implements A {
        @Override
        public int a() {
            return (new B()).a() + (new C()).a();
        }
    }


    static class D2 implements A {
        private B b;
        private C c;

        public D2(B b, C c) {
            this.b = b;
            this.c = c;
        }

        @Override
        public int a() {
            return b.a() + c.a();
        }
    }

    public static void main(String[] args) {
        B b = new B();
        C c = new C();
        D1 d1 = new D1();
        D2 d2 = new D2(b, c);
        
        System.out.format("B = %d%n", b.a());
        System.out.format("C = %d%n", c.a());
        System.out.format("D1 = %d%n", d1.a());
        System.out.format("D2 = %d%n", d2.a());
    }
}