Do we have static constructor in java?

Answer: No, we don’t have static constructor in java. Actually, java static constructor concept is not there. When we make a class constructor static, compiler will flash an error i.e.

“Illegal modifier for the constructor in type MyClass; only public, protected & private are permitted”.

In below example, at the compile time itself compiler will throw an error.

public class A {
	
	//static constructor
        //On making class constructor static, compiler will throw an error
	public static A(){
	
	}

}

Note: Instead of static constructor we can use static block in java

Related Posts