Java - What is the output: recursive constructor invocation?

Question

What is the output of the following code?

class Test {
  Test() {
    this();
    int k = 10; // First statement
    System.out.println("b");
    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();//recursive constructor invocation

Note

You cannot use this to call the constructor itself which will result in recursive constructor invocation.

Related Quiz