Reference to Base Class : Class Definition : Class C# Examples


C# Examples » Class » Class Definition »

 

Reference to Base Class









    
using  System;

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

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

class  Program
{
      static  void  Main()
      {
            DerivedClass  derived  =  new  DerivedClass();
            BaseClass  mybc  =  (BaseClass)derived;

            derived.Print();              
            mybc.Print();                    
      }
}
    
   
  
   



Output

This is the derived class.
This is the base class.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Class Definition