Home Java Javascript-array Java method overloading
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java method overloading

Advertisement
Example below demonstrates method overloading in java. In java method overloading means creating more than a single method with same name with different signatures. In the example three methods are created with same name.

Java method overloading

     

Example below demonstrates method overloading in java. In java  method overloading means creating more than a single method with same name with different signatures. In the example three methods are created with same name. Java understands these methods  with there signatures. Java identifies the methods by comparing their signatures like return types, constructor parameters & access modifier used.

 

 

 

 

 

Here is the code:

class Overload {
void test(int a) {
System.out.println("a: " + a);
}
void test(int a, int b) {
System.out.println("a and b: " + a + "," + b);
}
double test(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
class MethodOverloading {
public static void main(String args[]) {
Overload overload = new Overload();
double result;
overload.test(10);
overload.test(1020);
result = overload.test(5.5);
System.out.println("Result : " + result);
}
}

Output will be displayed as:

Java method overloading

Download Source Code

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 19, 2008

Ask Questions?    Discuss: Java method overloading   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Binod kumar
June 20, 2011
overload in java

i want to known all function of overload by the coding(programing). plz help my on my subject.
Himanshu Srivastava
September 6, 2011
Method Overloading

Iwant to know what is method overloading in java explain it frm basics.
vinodhini
December 28, 2011
hiiiiiiiii

its really very useful to me.........
mjagadesh
January 5, 2012
i need details about it

its easy
santhosh reddy WILLY
July 7, 2012
www.j2sejava.wordpress.com

hi very informative
Manpreet Singh
October 29, 2012
Compilation error

Exception in the thread ............!!! compilation error..this program is wrong
faustino,julius france o
December 5, 2012
java scripting

how to program a netpay using method overloading
Md. Danish Raza
December 5, 2012
java

i think you will give me all quetion to answer.
DMCA.com