Which of the following statements regarding constructor chaining in object-oriented...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which of the following statements regarding constructor chaining in object-oriented programming is/are FALSE?
I) To call more than two constructors of a class we must use constructor chaining.
II) We can place this() in all constructors in a class.
Show answer & explanation
Statement (I) is TRUE—constructor chaining allows calling multiple constructors in sequence through this() calls, forming a chain that terminates at a no-arg or parameterized base constructor. Statement (II) is FALSE—you cannot place this() in all constructors because at least one constructor must not call this() to avoid infinite recursion. Every chain must have a terminating constructor that initializes the object without further delegation.
Step-by-step Derivation:
Analysis of each statement:
Statement (I): "To call more than two constructors of a class we must use constructor chaining."
- Constructor chaining enables calling multiple constructors: Constructor A → this() → Constructor B → this() → Constructor C.
- Example: Constructor(int), Constructor(int, String), Constructor(int, String, boolean) can all be chained.
- This statement is TRUE. Constructor chaining is the mechanism that allows this.
Statement (II): "We can place this() in all constructors in a class."
- If every constructor calls this(), there is no base constructor to terminate the chain.
- Result: Infinite recursion → StackOverflowError.
- At least ONE constructor must NOT call this() (the terminating constructor).
- This statement is FALSE.
Conclusion: Only (II) is false, so the answer is B.