nerdexam
Oracle

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.

Working with Inheritance

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)
  • A
    3% (1)
  • C
    3% (1)
  • D
    95% (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.

AIt can take arguments.

A default constructor, by definition, is a no-argument constructor generated by the compiler if no other constructors are explicitly defined in the class.

BIt has private access modifier in its declaration.

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.

CIt can be overloaded.

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.

DThe default constructor of a subclass always invokes the no-argument constructor of itsCorrect

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

#constructors#default constructor#superclass constructor

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice