← Back to libraryQuestion 23 of 273
JavaIntermediate

Constructor Chaining

📖 Detailed Explanation:

Constructor chaining is calling one constructor from another. Within the same class: use 'this()'. Between parent and child: use 'super()'. This pattern promotes code reuse and ensures proper object initialization through a sequence of constructors.

🌍 Real-World Example:

A constructor initializing default values, and another constructor accepting parameters, both ensuring the object is in a valid state.

🎯 Scenario-Based Interview Question:

Why must 'this()' or 'super()' ALWAYS be the first statement in a constructor?