Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Past Java exam about constructors

Tags:

java

I am going through a past Java exam and I have a question that I'm stuck on.

The question is: "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?

Thanks for your answers!

like image 945
Paldan Avatar asked Oct 20 '13 13:10

Paldan


1 Answers

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.

like image 57
Mateusz Dymczyk Avatar answered Sep 20 '22 17:09

Mateusz Dymczyk