javaconstructorempty-class

I am creating an empty Java class and compiling it, will any constructor be created


I am creating an empty Java class and compiling it, will any constructor be created as it is being compiles successfully

Class ABC{

}


Solution

  • If a class contains no constructor declarations, then a default constructor with no formal parameters and no throws clause is implicitly declared.

    So, the compiler will put the default constructor for you if you won't put any constructors.

    So your class will be like:

    class ABC {
    
        public ABC() {
    
        }
    }