public class A {
public A(int x) { System.out.print("A" + x + " "); }
}
public class B extends A {
public B(int x) {
System.out.print("B" + x + " ");
super(x);
}
}What occurs?
- A
Prints 'B1 A1 '
- B
Prints 'A1 B1 '
- Ccheck_circle
Compile error: super(...) must be the first statement
- D
Runtime error
Explanation
super(...) calls must be the first statement in a constructor. Otherwise, the compiler reports an error.