oop - Different kinds of instance of Child- Parent class hierarchy in c# -
i want know relation between instances of parent child in c#.
suppose have 2 classes base , derived:
base b = new base() derived d = new derived() derived db = new base() base bd = new derived()
then meaning of above types of objects
please suggest confused.
assuming base base class of derived....
line 1 contains instance of base class.
line 2 contains instance of derived class.
these both "standard" variables, variable type matches instance contains.
line 4 instance of derived class, restricted accessing base class methods. think of restricted view of derived class.
line 3 should produce compilation error. can't place instance of base class in variable of more restrictive type. think of "all dogs(derived class) animals(base class), not animals dogs.
Comments
Post a Comment