new method : Override : Class C# Examples


C# Examples » Class » Override »

 

new method









    
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
{
      new  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

B.DoSomething
A.DoSomething


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Override