Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Overloading Examples

 
Dinakar Manchikalapudi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain what a method overloading is with the help of a simple example?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving this to the Java In General (Beginner) forum.

Thanks

Mark
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic