Home > DeveloperSection > Articles > Method Overriding in C# Net

Method Overriding in C# Net


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

Method Overriding in C#.Net


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

        }

    }

 


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

Follow MindStick