What happens if no constructor is provided in a Java class?

  • The class cannot be instantiated, and objects of that class cannot be created.
  • Java automatically provides a default no-argument constructor for the class.
  • The class can only be instantiated by other classes in the same package.
  • The class becomes a singleton by default.
a) is correct. If no constructor is provided in a Java class, Java automatically provides a default no-argument constructor. b) is a common misconception; Java only provides a default constructor if you haven't defined any constructors explicitly. c) and d) are incorrect statements.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *