Answer the question
In order to leave comments, you need to log in
Inheritance of private fields?
I've been studying C# for a while and settled on the "inheritance" chapter, perhaps later this issue is considered in more detail, but I would like to receive an answer now
class B
{
private int b;
public int GetSetb { get { return b; } set { b = value; } }
}
class C : B
{
}
Answer the question
In order to leave comments, you need to log in
The child class does not know anything about the parent's private fields, and may contain fields/methods/properties of the same name, and not necessarily of the same type and with the same access modifier.
When you create a variable with the type of a child class, then all parent constructors work out for you, and all fields of parent classes are created in memory. They are required for all inherited methods and properties to work, but private fields cannot be directly accessed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question