更新时间:2022-06-18 08:48:32
例如:
public class Example {
public static void main(String...args) {
new C();
}
public static class A {
public A() {
System.out.println("A");
}
}
public static class B extends A {
public B() {
System.out.println("B");
}
}
public static class C extends B {
public C() {
System.out.println("C");
}
}
}
另请注意,这可能不会打印出您所期望的内容.它实际上会打印:
Also note that this might not print what you would expect. It would actually print:
A
B
C
为什么?构造函数总是链接到超类.
Why? Constructors are always chained to the super class.