Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protected data members and data functions

when i declare a protected data member in a class that means its not accesible to the outer world but the derived class. My question is

will it be accesible to a class that is derived from the derived class?

like image 906
Saad Masood Avatar asked Dec 21 '22 20:12

Saad Masood


2 Answers

Yes, protected data members are accessible all the way down the inheritance hierarchy.

Protected data is usually better avoided. An alternative is to write protected methods that access the private data. This keeps the data encapsulated within a single class. It also makes it easy to set a breakpoint for changes to the data.

like image 53
Andy Thomas Avatar answered Dec 31 '22 00:12

Andy Thomas


Yes. (You could have simply tried that out, by the way.)

like image 37
EboMike Avatar answered Dec 31 '22 00:12

EboMike