Paldan
Paldan

Reputation: 435

What do you call the process of constructors calling constructors for their parent class in Java?

I saw this question on a Java exam:

Any constructor either explicitly or automatically calls the constructor of its parent class, which calls its parent, and so on up the class hierarchy. What is the name of this process?

Upvotes: 10

Views: 373

Answers (1)

Mateusz Dymczyk
Mateusz Dymczyk

Reputation: 15141

It's called "constructor chaining"

@Edit: adding source: Oracle's documentation. Courtsey of Oli Charlesworth.

If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, you might think that there will be a whole chain of constructors called, all the way back to the constructor of Object. In fact, this is the case. It is called constructor chaining, and you need to be aware of it when there is a long line of class descent.

Upvotes: 15

Related Questions