Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Are method overloading and overriding same thing? If not, what is the difference?
Does this concept apply to any programming language?

No, they are not same.
Consider a method add().
1. Overloading - When a method is overloaded it necessarily means that it is another method.
ex: add( a, b );
and
add( a, e, f );where a, b are integers, while e and f are real numbers.
As soon as the compiler comes across these function call, it is able to resolve the two different function calls,
here add( integer, integer );
and add( integer, real, real );are two difserent functions( methods ) with different function definitions in the code segment.
2. Coming to Overriding, you are calling the same method in different contexts.
say you have a data type which can take a generic value
add( generic_data_type, generic_data_type );
Now when add is called with add( 12, 20 );
The compiler resolves this to be
add( integer, integer ); at Runtime and not at compile time.so in case of method overriding the compiler cannot place the function definition. It can only do so at run-time, this funda is called late-binding or dynamic binding.
B'coz the arguments cannot be binded to any data-type during compile time.
This the sample of Overriding and overloading funda.
===============================
A real world exampleYour name is Kora .L. ( here L is u'r initials ).
Consider other names like
Kora R. Y
Kora M
etc.Here Kora L, Kora R Y, Kora M are different individuals, Kora is the only thing in common.
We can easily resolve this. - This is called function OVERLOADING.
But consider yourself being called as
Kora by your old classmates.
Mike by your Collegues
Sweet Heart by your beloved.Now You the same person is referred to by different versions in different contexts, this is function OVERRIDING.
-GOOD LUCK

![]() |
Allegro problem
|
Access to Foxpro Accessin...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |