Home > DeveloperSection > Blogs > Concept of Overriding

Concept of Overriding


C# C# 
Ratings:
0 Comment(s)
 2163  View(s)
Rate this:

Method Overriding:

 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):

}


Don't want to miss updates? Please click the below button!

Follow MindStick