Group Group Group Group Group Group Group Group Group

UseCase for private for the constructor that has a subclass

On page 241 for the 2nd edition, super class User has a private member id. Subclass PrivilegedUser needs id. As id cannot be used within this subclass, does this kind of defining a private variable at the super class has any value.

Thanks for the question @pgudivada!

If the parent class has a property marked private, that property can be used within methods of the parent class. In the example in the book, the parent class User did not have any methods of its own, but if it did, those methods would have access to the private variable at the super class level.

Thanks again!