Multiple choice technology web technology

package simplejava; public class TestConstructor1 { int p; TestConstructor1() { System.out.println("I am in Constructor"); } TestConstructor1(int p) { this.p =p; System.out.println("p = "+p); this(); } public static void main(String[] args) { TestConstructor1 tp1 = new TestConstructor1(10); } }

  1. p = 10

  2. p = 0

  3. Compiler Error

  4. Exception

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, a constructor call (this()) must be the first statement in a constructor. Here, the parameterized constructor attempts to assign this.p=p and print before calling this(), which violates this rule. The compiler enforces that constructor chaining happens first.