What is the use of this()?
-
constructor
-
Destructor
-
Class
-
method
Reveal answer
Fill a bubble to check yourself
A
Correct answer
Explanation
The this() keyword is used to call another constructor in the same class, enabling constructor chaining. It must be the first statement in a constructor and helps avoid code duplication when multiple constructors share common initialization logic.
AI explanation
this() is used inside a constructor to call another constructor of the same class (constructor chaining), letting one constructor reuse initialization logic from another. It must be the first statement in the constructor body. It has nothing to do with destructors, classes in general, or ordinary methods, which is why those options are wrong.