Home Java Javascript-array Java method overloading



Java method overloading
Posted on: November 19, 2008 at 12:00 AM
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

Related Tags for Java method overloading:
javacdiffmethodsloadmethodoverloadingnameloadingcreateifexamplesignaturewithnatexamsingleesignoverloaditdemoindifferentmnttrjadessignaturesemovermemeanhrrateratescreatingsamexaxampscreatedeeathamplerlerleaarstrsavassamssamrenthavbelostatifepleplodsono


More Tutorials from this section

Ask Questions?    Discuss: Java method overloading   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.