Friday, May 4, 2012

Overloading in Inheritance

This Article will explain you how we can achieve Overloading in  Inheritance

 public class Base  
   {  
     public Base()  
     { Console.WriteLine("Base Constructor"); }  
     public void display()  
     {  
       Console.WriteLine("Nirbhay from base");  
     }  
   }  
 -------------------------------------------------------------------------------------------------------------  
   public class Child:Base  
   {  
     public Child()  
     {  
       Console.WriteLine("Child Constructor");  
     }  
     public void display(string name)  
     {  
       Console.WriteLine("Child " + name);  
     }  
     public void display(int number)  
     {  
       Console.WriteLine("Child " + number);  
     }  
   }  
 --------------------------------------------------------------------------------------------------------------  
  class Program  
   {  
     static void Main(string[] args)  
     {  
       Child obj = new Child();  
       obj.display();  
       obj.display(12);  
       obj.display("nirbhay");  
       Console.ReadLine();  
     }  
   }  

No comments:

Post a Comment