What happens if a Java class has no constructors defined?
2025
What happens if a Java class has no constructors defined?
- A.
The compiler throws an error
- B.
The compiler adds a default constructor automatically
- C.
A parameterized constructor is added by default
- D.
The object cannot be created using new keyword
- E.
Only static methods can be accessed
Attempted by 67 students.
Show answer & explanation
Correct answer: B
Correct answer: The compiler adds a default constructor automatically.
If no constructor is declared in a Java class, the compiler provides a default no-argument constructor. This lets objects be created normally unless another declared constructor changes the situation.
Loading lesson…