Java - What is the output: static Constructor?

Question

What is the output of the following code?

class Test {
  public static Test(int x) {
    if (x < 0) {
      return;
    }
    System.out.println(x);
  }
}

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


Click to view the answer

public static Test(int x) {

Illegal modifier for the constructor in type Test; only public, protected & private are permitted

Note

Constructors are used in the context of the creating a new object.

You cannot declare a constructor static.

Related Quiz