146k views
2 votes
If you don't supply a constructor, what happens?

a. A default constructor is provided automatically
b. The program won't compile
c. An error message is displayed
d. The constructor from the superclass is used

1 Answer

4 votes

Final answer:

If you don't supply a constructor for a class, a default constructor is provided automatically by the compiler that calls the superclass constructor with no arguments.

Step-by-step explanation:

If you don't supply a constructor in a class, a default constructor is provided automatically by the compiler. This default constructor is a no-argument constructor that calls the constructor of its superclass with no arguments.

If a superclass does not exist, then the default constructor calls the constructor of the Object class, as it's the base class for all objects in Java. In languages like C++ or Java, providing an explicit default constructor is only necessary if you require a constructor to perform certain actions or initialize member variables to specific values.

User Trbaphong
by
7.5k points