Tuesday 4 October 2011

Difference between method overriding and overloading

Overriding is the concept of having functions of same name and signature in different classes. one in the super class can be made virtual and other can override the functionality of virtual one.

Overloading is the concept of having functions of same name, but different signature in same class. They are differentiated by the compiler by their signatures


There is big difference between both:

 When overriding, you change the method behavior for a derived class.
e.g Clas A
{
Virtual void hi(int a)
{
}
}

Class B:A

{
public overrid void hi(int a)
{

}

}

Overloading simply involves having a method with the same name within the class.


Example for Over loading


Class A

{
class a()

{


}

class a(int a)
{
}
}

No comments:

Post a Comment