1Z0-803 · Question #159
Which statement is true about the default constructor of a top-level class?
The correct answer is D. The default constructor of a subclass always invokes the no-argument constructor of its. The default constructor of a subclass implicitly calls the no-argument constructor of its immediate superclass before executing its own constructor body.
Question
Which statement is true about the default constructor of a top-level class?
Options
- AIt can take arguments.
- BIt has private access modifier in its declaration.
- CIt can be overloaded.
- DThe default constructor of a subclass always invokes the no-argument constructor of its
How the community answered
(40 responses)- A3% (1)
- C3% (1)
- D95% (38)
Why each option
The default constructor of a subclass implicitly calls the no-argument constructor of its immediate superclass before executing its own constructor body.
A default constructor, by definition, is a no-argument constructor generated by the compiler if no other constructors are explicitly defined in the class.
The default constructor's access modifier is the same as the class itself; it is typically public for a public class or package-private for a non-public top-level class, not private.
While a class can have overloaded constructors, the compiler-generated default constructor itself is always no-argument and cannot be overloaded; if you define any constructor, the default constructor is not generated.
Every Java constructor, including a compiler-generated default constructor, must explicitly or implicitly invoke a superclass constructor as its first statement; if no `super()` or `this()` call is present, the compiler automatically inserts `super()`.
Concept tested: Java default constructors and superclass invocation
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html
Topics
Community Discussion
No community discussion yet for this question.