我有一个类,包含许多内部类 这个内部类之一是一个子类,有很多孩子 像这样:
class BigClass {
A a;
B b;
C c[] = new C[3];
class A {}
class B {
A a1;
}
class C {
B b1;
}
class c1 extends C {}
class c2 extends C {}
class c3 extends C {}
}
当所有类都链接到每个类时,如何从BigClass创建一个对象?
答案 0 :(得分:0)
这是一个工作方法,演示如何实例化每个类并分配变量。将此方法添加到BigClass
类,以便您可以将其作为程序运行。
public static void main(String[] args)
{
BigClass big = new BigClass();
A a = big.new A();
big.a = a;
B b = big.new B();
b.a1 = a;
big.b = b;
C c = big.new C();
c.b1 = b;
big.c[0] = c;
c1 c1 = big.new c1();
big.c[0] = c1;
c2 c2 = big.new c2();
big.c[1] = c2;
c3 c3 = big.new c3();
big.c[2] = c3;
}