Breaking News
Loading...
Friday 29 March 2013

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@\/  <(.'.)>

0 comments:

Post a Comment

Thanks for comment

 
Toggle Footer