Private Versus Protected
You may have noticed that a new access keyword, protected, has been introduced on lines 23 and 43 of Listing 16.1. Previously, class data had been declared private. However, private members are not available to derived classes. You could make itsAge and itsWeight public, but that is not desirable. You don't want other classes accessing these data members directly.
What you want is a designation that says, “Make these visible to this class and to classes that derive from this class.” That designation is protected. Protected data members and functions are fully visible to derived classes, but are otherwise private.
There are, in total, three access specifiers: public, protected, and private. If a function has an instance ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access