[Solved] Why Protection() Constructor is getting executed multiple times? (Especially, base constructor getting executed twice in the beginning of the output) [closed]


The Protection constructor gets executed multiple times because you instantiate multiple objects of Protection.

Each time you call new Protection(); the Protection constructor runs.

You call it first in Demo, then you instantiate Derived and since Derived extends Protection so the Protection constructor gets called once more. And finally when you instantiate SamePackage and SamePackage instantiates Protection as well, the constructor gets called a third time.

I hope this is understandable…

6

solved Why Protection() Constructor is getting executed multiple times? (Especially, base constructor getting executed twice in the beginning of the output) [closed]