Wednesday, 19 August 2015

What is difference between overloading and overriding in c#.net

Overloading : 
  • Overloading is an approach of defining multiple methods with the same name changing their signature.
  • This can be done within the class as well as child class also.
  • To overload a method in the child class we don't require any permission  from parent class.              
 Overriding :   
  •  Overriding is an approach of defining multiple methods with the same name and same signature.
  • This can be done only within the child class.
  • To override a method in the child class we require an explicit permission from permission from parent class.
     signature is nothing but a changing the signature in the sense we can either change the  number of parameters being passed to the method  (or) type of parameter pass to method (or) order parameter being passed to the method.

     example : 
  • public void show();
  • public void show(int x);
  • public void show(string x);
  • public void show(int x, int y);
  • public void show(string x, int x); and soon...... 

4 comments: