Let us say we have to call the base class method from the derived class objects.
So we need to Typecast the derived class object to the base class and then call the method of base class
Lets see the code
- using System;
- public class BaseClass
- {
- public void Method1()
- {
- Console.WriteLine("Base class Method....");
- }
- }
- public class DerivedClass: BaseClass
- {
- public new void Method1()
- {
- Console.WriteLine("Derived class Method....");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- DerivedClass derivedObj = new DerivedClass();
- BaseClass obj2 = (BaseClass) derivedObj;
- obj2.Method1();
- }
- }
Hope you got the concept .Thanks for reading.