While reading this polymorphism i found below line of statement which says that, if i will type cast derived class object as base class then it will call base class method, but without casting it calling to the base method then what's meaning of type casting?
Hidden base class members may be accessed from client code by casting the instance of the derived class to an instance of the base class. For example:
DerivedClass B = new DerivedClass();
B.DoWork(); // Calls the new method.
BaseClass A = (BaseClass)B;
A.DoWork(); // Calls the old method.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 038b0638-2d29-8c0f-9f50-03aaedd907cb
Version Independent ID: a1528e47-f01c-2e6c-d12f-9c8b15e11711
[Enter feedback here]
Hi,
While reading this polymorphism i found below line of statement which says that, if i will type cast derived class object as base class then it will call base class method, but without casting it calling to the base method then what's meaning of type casting?
Hidden base class members may be accessed from client code by casting the instance of the derived class to an instance of the base class. For example: DerivedClass B = new DerivedClass(); B.DoWork(); // Calls the new method.
BaseClass A = (BaseClass)B; A.DoWork(); // Calls the old method.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.