I have read that private variables in a base class are technically inherited by child classes, but are not accessible.
If this is correct, why do we say they are inherited when presumably they can only be accessed by reflection?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Subclassing is about inheriting implementation; and fields are an implementation detail.
The fields are indeed present, and are available via reflection. But ultimately, it is the base-classes job to manage the state of those fields via any public/protected/etc members.
But ultimately – if a base-class declares a property (and field) for property
Foo, then when you set that property the data has to go somewhere. The sub-class has to include all the fields from the base-class for it to make sense. This is also critical for field-based serialization frameworks (such asBinaryFormatter).