在Java中,super关键字在构造器中的使用有两种情况:
public class Parent {
public Parent() {
System.out.println("Parent constructor");
}
}
public class Child extends Parent {
public Child() {
super(); // 调用父类构造器
System.out.println("Child constructor");
}
}
public class Outer {
private int x;
public Outer(int x) {
this.x = x;
}
public class Inner {
private int y;
public Inner(int y) {
Outer.this.x = y; // 调用外部类的构造器
this.y = y;
}
}
}