Interview Question

What is constructor chaining?

Constructor chaining uses this() or super() to share initialization.

💡 Concept ✅ Quick Revision ☕ Java

Answer

Constructor chaining is one constructor invoking another constructor to reuse initialization. • this(...) calls another constructor in the same class. • super(...) calls a direct-superclass constructor. • The chain must eventually reach an Object constructor and cannot form a cycle.

Example

Code
class Point {
    Point() { this(0, 0); }
    Point(int x, int y) { System.out.println(x + "," + y); }
}
new Point();
Output
0,0

Quick Revision

Constructor chaining uses this() or super() to share initialization.