Java - What is the output: static Constructor?


What is the output of the following code?

class Test {
  public static Test(int x) {
    if (x < 0) {

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


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

You cannot declare a constructor static.

Related Quiz