Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why private members get inherited?

So private members in the base class are also in the inherited class but not accessible in it, right?
Are they actually in the memory allocated to the the inherited object?

like image 259
Memo Avatar asked Dec 07 '22 05:12

Memo


1 Answers

Are they actually in the memory allocated to the the inherited object?

Yes, they need to exist. The private members are part of the implementation detail of the base class. Without them, in general, the base class wouldn't be able to function (which is why they exist in the first place).

Making them private just allows the base class to create its implementation however it chooses, without exposing that to anybody, including the subclass.

like image 160
Reed Copsey Avatar answered Dec 30 '22 02:12

Reed Copsey