4

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?

Saad Masood
  • 11,036
  • 9
  • 32
  • 40

2 Answers2

6

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.

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
2

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

EboMike
  • 76,846
  • 14
  • 164
  • 167