Question 1
What is the result of compiling the following program? ```java public class Main { Main() { System.out.print("A"); this(5); } Main(int x) { System.out.print("B"); } public static void main(String[] args) { new Main(); } } ```
A. AB
The code never runs; a this() call must be the first statement, and here a print precedes it.
B. BA
The constructor does not compile because this(5) is not the first statement, so no output is produced.
C. Compilation failsCorrect answer
An explicit this(...) invocation must be the first statement of the constructor, but a print precedes it here.
D. A
The misplaced this() call is a compile error, so nothing prints.
Explanation
An explicit constructor invocation — this(...) or super(...) — must be the FIRST statement of the constructor. Here a print precedes it, so the compiler rejects it ("call to this must be first statement in constructor").