Java - What is the output: this constructor call?

Question

What is the output of the following code?

class Test {
  Test() {
    System.out.println("a");
    int k = 10; 
    System.out.println("b");
    this(k); 
    System.out.println("c");
  }

  Test(int x) {
    System.out.println(x);
  }
}

public class Main {
  public static void main(String[] args) {
    new Test();
  }
}


Click to view the answer

this(k); // Second statement. A compile-time error

Note

A call to the constructor with int parameter this(k) is not the first statement inside the constructor's body.

Related Quiz