Home > DeveloperSection > Forums > How to use override concept using virtual keyword in C#
Ankit Singh

Total Post:341

Posted on    January-03-2016 10:59 PM

 C# C#  OOPS 

 1 Reply(s)
 316  View(s)
Rate this:
I want to use use  override  concept using  virtual  keyword in C#.how to do this please help me.

aditya kumar Patel

Total Post:253

Posted on    January-03-2016 11:08 PM

 we know overriding is the concepts of OOPS which is implement using abstract method and virtual class keyword . for more description goto  https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx .
 Let's see on virtual and override keywords in C# .

try to how can do show below

using System;

namespace Verriding
    class first
        public virtual void method() { Console.WriteLine("called class first method()"); }

    class second : first
        public override void method() { Console.WriteLine("called class second method()"); }

    class third : second
        public override void method() { Console.WriteLine("called class third method()"); }

    class Program
        static void Main(string[] args)

            first a = new first();
            second b = new second();
            third c = new third();
            a.method(); // output --> "first::method()"
            b.method(); // output --> "second::method()"
            c.method(); // output --> "third::method()"
            a = new second();
            a.method(); // output --> "second::method()"
            b = new third();
            b.method(); // output --> "third::method()"


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

Follow MindStick