Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on Difference between method overriding and overloading within the OOPS forums, part of the Software Development category; Originally Posted by nancyphilips Is the concept of method overriding different from the concept of overloading. If so how they both differ. Function Overriding: In a child class, redefining the ...
|
|||||||
|
|||
|
Re: Difference between method overriding and overloading
Quote:
class MyParent: { virtual Func() { print "Hello World"; } }; class MyChild : public MyParent { // Default behavior of Func is (parent supplied) "Hello World" //Redefining parent supplied behavior Func() { Calculate equations; print equations;} } --------------------- Function Overloading: Has nothing to do with inheritance. This is the ability that the programming language offers you, by which you can reuse the lable name of the function to perform different tasks at different times. For example: class MyClass { int MyOLFunction () { print "Hello World"; return 0;} int MyOLFunction (int x) { print "Hello World" x number of times; return 0;} int MyOLFunction (char a) { print "Hello World"; print a; return 0;} //Note: The following are not function overriding, and will generate compile time error long MyOLFunction () { print "Hello World"; return 0;} // Error char MyOLFunction () { print "Hello World"; return 0;} // Error }; |
| Sponsored Links |
|
|||
|
Re: Difference between method overriding and overloading
Overriding means modifying or enhancing the method implementation in derived class.
Overloading means class have more than one method having same name but different implementation or different number of input parameters with different return type. |
|
|||
|
Re: Difference between method overriding and overloading
* Overloading deals with multiple methods in the same class with the same name but different signatures
* Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature * Overloading lets you define a similar operation in different ways for different data * Overriding lets you define a similar operation in different ways for different object types |
|
|||
|
Re: Difference between method overriding and overloading
when ever we want code refinement(means some changes in method body) then that time we r using overloding
when ever we want cod replacement(means totally changes body) then that time we r useing overriding |
|
|||
|
Re: Difference between method overriding and overloading
differences are as follows:
OVERLOADED OVERRIDING 1.)arguments- can change must not change 2.)exceptions-can change cant change except for covariant returns 3.)invocation-reference type determines which overloaded version is selected at compile time .the actual method tht is invoked is still svirtual method invocation that happens at runtime but the compiler will already know the signature of the method to be invoked .so at the runtime the argument match will already have been nailed down but in overriding object type determines which methjod is selcted happens at runtime |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|