blog

Home / DeveloperSection / Blogs / Concept of Overriding

Concept of Overriding

Anonymous User3908 07-Oct-2010

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

Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By