Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Method Overloading Examples

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain what a method overloading is with the help of a simple example?
 
author & internet detective
Posts: 40797
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dinakar,
Welcome to JavaRanch!

Method overloading is when you have two or more methods with the same name and different arguments. There are many examples in articles on the subject. Do you have a more specific question on this?
 
Dinakar Manchikalapudi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hii Jeanne,
Thanks for yr reply. I was looking for some sample code for overloaded methods. Does the overloaded method need to be in the same class?

Thanks,
Dinakar.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am moving this to the Java In General (Beginner) forum.

Thanks

Mark
 
Jeanne Boyarsky
author & internet detective
Posts: 40797
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dinakar Manchikalapudi:
I was looking for some sample code for overloaded methods. Does the overloaded method need to be in the same class?


The article I linked to contains sample code. The overloaded method needs to be in the same class (or subclass). If they weren't, they would just be two methods that happened to have the same name.
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Method overloading is a method with same name but with different parameters. For eg


Corresponding method will be called based on parameters that you are passing. For eg, if you call add(3.0,5.0) in your program
double version of the add method will be invoked

i hope it helps you understand the overloading concepts.
Mostly overloading will be used in the same class.

bye for now
sat
 
reply
    Bookmark Topic Watch Topic
  • New Topic