HOW TO USE OVERRIDE CONCEPT USING VIRTUAL KEYWORD IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#  OOPS 
C#
 560  View(s)
Ratings:
Rate this:
I want to use use  override  concept using  virtual  keyword in C#.how to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use override concept using virtual keyword in C#

     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()"

                Console.ReadKey();
            }
        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!