Users Pricing

articles

home / developersection / articles / method overriding in c# net

Method Overriding in C# Net

Uttam Misra 7222 16 Jul 2010 Updated 04 Mar 2020

Overriding a method is to change the behavior of the method for the derived class.

Overriding is done using inheritance and virtual functions

Example

To explain the concept of overriding I have created two classes Poly

and abc(inherits poly).

    public class poly
    {
//these two functions, sum(), are overloaded.
        public int sum(int x, int y)
        {
            return (x + y);
        }
        public virtual int sum(int x, int y, int z)
        {
            return (x + y + z);
        }
    }
 
    public class abc : poly
    {
//overriding function sum(), of base class poly
        public override int sum(int x, int y, int z)
        {
            return (x + y + z + 10);
        }
    }

 

 


Uttam Misra

Information Technology

More than 18 years of working experience in IT sector. We are here to serve you best.


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md