What is Method Overriding in.Net?, How to use Method Overriding in.Net?


In method overriding there is parent class has a method(function) with virtual keyword and this method is overridden in child class.as shown in example

Example:

namespace CA_Method_overriden
{
    class student
    {
        public int age;
        public string name;
        public virtual string mark()
        {
            return "35";
        }
    }
    class girlstudent : student
    {
        public override string mark()
        {
            return "50";
        }
    }
    class boystudent : student
    {
        public override string mark()
        {
            return "70";
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            girlstudent objgs = new girlstudent();
            Console.WriteLine(objgs.mark());

            boystudent objbs = new boystudent();
            Console.WriteLine(objbs.mark());
        }
    }
}

OUTPUT:

50
70

See Also :
  Follow Me On Facebook
--
/\/ir@\/  <(.'.)>

Comments

Popular posts from this blog

How to make and use web service in Microsoft Dynamics Navision.

How to use Format function in Microsoft Dynamics Navision.

How to create simple report in Microsoft Dynamics Navision.