Method Overriding is a technique that allows the use of any functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called method overriding. This is like a virtual method.
using System;
class baseClass
{
public virtual void show()
{
Console.WriteLine("Base class");
}
}
class derived : baseClass
{
public override void show()
{
Console.WriteLine("Derived class");
}
}
class GFG
{
public static void Main()
{
baseClass obj;
obj = new baseClass();
obj.show();
obj = new derived();
obj.show();
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Method Overriding is a technique that allows the use of any functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called method overriding. This is like a virtual method.