Polymorphism and Virtual Functions : Abstract Class : Class C# Examples


C# Examples » Class » Abstract Class »

 

Polymorphism and Virtual Functions









    
using  System;

public  abstract  class  Clock  {
        public  abstract  void  Play();
}

public  class  RedClock:  Clock  {
        public  override  void  Play()  {
                Console.WriteLine("RedClock.Play()");
        }
}
public  class  BlueClock:  Clock{
        public  override  void  Play()  
        {
                Console.WriteLine("BlueClock.Play()");
        }
}
class  MainClass
{
        public  static  void  CallPlay(Clock  ms)
        {
                ms.Play();
        }
        public  static  void  Main()
        {
                Clock  ms  =  new  RedClock();
                CallPlay(ms);
                ms  =  new  BlueClock();
                CallPlay(ms);
        }
}
    
   
  
   



Output

RedClock.Play()
BlueClock.Play()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Abstract Class