Method overriding isthe mechanism same method name with same arguments and return types associatedin a class and its subclass. Overriding is mainly used in functions.Overriding is an object-oriented programming feature that enables a child class to provide different implementation for a method that is already defined and/or implemented in its parent class or one of its parent classes. The overriden method in the child class should have the same name, signature, and parameters as the one in its parent class.
Only those methods are override that methods are declaredwith keyword virtual in the base class.
Example:
Class A
{
Virtual void add(int a, int b)
{
Return(a+b);
}
}
Class B:A
{
Public override void mul(int a, int b)
{
Return(a*b);
}
}
Static void main()
{
A obj=new A()
Obj.add(5,6);
B obj1=new B();
Obj.mul(5,9):
}
Anonymous User
06-Feb-2019Thank You for the information.
Manish Kumar
13-Jun-2017Your words increase my knowledge for sure. Thanks