• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic