asked 11.4k views
3 votes
if super is used in the implementation of a subclass constructor, it must be used in the first line of the constructor body. T/F?

asked
User Nivcaner
by
8.2k points

1 Answer

6 votes

Answer:

True. When using the "super" keyword in the implementation of a subclass constructor, it must be used in the first line of the constructor body.

Step-by-step explanation:

The "super" keyword is used to invoke the constructor of the superclass (i.e., the parent class) from within the subclass constructor. By calling "super" as the first line of the subclass constructor, it ensures that the superclass constructor is executed before any other code in the subclass constructor. This allows for proper initialization of the inherited attributes and any additional setup required by the superclass.

If "super" is not called as the first line of the subclass constructor, the compiler will automatically insert it as the first line of code in the constructor. Thus, it is a requirement to use "super" in the first line of the constructor body to ensure the proper execution of the superclass constructor.

answered
User Diego Palomar
by
8.7k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.