wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Overloading methods,constructors. Can't seem to find the reason for doing this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overloading methods,constructors. Can Watch "Overloading methods,constructors. Can New topic
Author

Overloading methods,constructors. Can't seem to find the reason for doing this

Chris Creed
Ranch Hand

Joined: Feb 27, 2009
Posts: 67

Hey all

Doing some boning up to get myself back into the Java programming game, and in my attempt been doing some tutorials and what not. One of the things that I've come across that never seems to be explained to me is the reason why you woudl overloading a method or constructor. Can someone give me a real life example of why this would be done or suggested?

Thanks in advance

cc
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Chris Creed wrote:One of the things that I've come across that never seems to be explained to me is the reason why you woudl overloading a method or constructor. Can someone give me a real life example of why this would be done or suggested?



My teacher gave us a very simple example of method overloading during my early days of OO programming. She said, consider a class having a method to add which makes addition of two integers, so you define something like this,



But what I want to add two floats numbers, I cant use the same method, So having the OOP concept , method overloading, we can have a same method named add but with different signature,



Now, you can say like, we can define generic function for this, But this is simplest and basic example of method overloading !!

Ok, this my try, and you will get some beautiful explanation from my fellow Ranchers ..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
Don't get me started about those stupid light bulbs.
 
subject: Overloading methods,constructors. Can't seem to find the reason for doing this
 
Similar Threads
Stringbuffer as SQL string?
byte compound assignment very strange
Any one solve it?
Update query
Overriding