Tuesday, November 29, 2011

METHOD OVERRIDING IN C#.

/*
  Method Overriding :- The methods having same name , same signature
  but in different class & different implementation.

    Overloding        Overriding
    ==========        ===========
   1. In single class           1. Minim. Two class
   2. Different signature     2. Same signature
*/
//parent class
class a
{
    public virtual void display()
    {
        System.Console.WriteLine("base class");
    }
}
//child class
class b : a
{
    public override void display()
    {
        System.Console.WriteLine("child class");
    }
}   
class c
{
    public static void Main()
    {
        b z=new b();
        z.display();
       
    }
}
   
        

METHOD OVERLOADING IN C#.

//Method Overloding :
//The Methods having the same name .. but different signature
//Signature : Number of parameters and Types of parameters
//Return type is not included in signature..
//Return type change : not overloding ...erororororo
class a
{
    //private attribute
    int x;
    public void display()
    {
        x=9999;
        System.Console.WriteLine("x="+x);
    }
    /* erorororororooror
    public int display()
    {
        x=9999;
        System.Console.WriteLine("x="+x);
        return 999;
    }
    */
    public void display(int p)
    {
        x=p;
        System.Console.WriteLine("x="+x);
    }
    public void display(int p,int q)
    {
        x=p+q;
        System.Console.WriteLine("x="+x);
    }
}
class b
{
    public static void Main()
    {
        a z=new a();
        z.display();
        z.display(222);
        z.display(33,33);
       
    }
}