Three-level Override methods : Override : Class C# Examples


C# Examples » Class » Override »

 

Three-level Override methods









    
using  System;

class  BaseClass
{
      virtual  public  void  Print(){  
            Console.WriteLine("This  is  the  base  class.");  
      }
}

class  DerivedClass  :  BaseClass
{
      override  public  void  Print()  {  
            Console.WriteLine("This  is  the  derived  class.");  
      }
}

class  SecondDerived  :  DerivedClass
{
      override  public  void  Print()
      {
            Console.WriteLine("This  is  the  second  derived  class.");
      }
}

class  MainClass
{
      static  void  Main()
      {
            SecondDerived  derived  =  new  SecondDerived();
            BaseClass  mybc  =  (BaseClass)derived;
  
            derived.Print();
            mybc.Print();
      }
}
    
   
  
   



Output

This is the second derived class.
This is the second derived class.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Override