Comment on Tutorial - Method Overloading sample in Java By Ganesh Iyer



Comment Added by : ITMIT

Comment Added at : 2011-06-05 19:16:46

Comment on Tutorial : Method Overloading sample in Java By Ganesh Iyer
public class Overload2 {

void add(int m, int n)
{
int sum = m + n;
System.out.println( "Sum of a+b is " +sum);
}

void add(int a, int b, int c) {

int sum = a + b + c;
System.out.println("Sum of a+b+c is " +sum);

}

void add(double a, double b) {

double sum = a + b;
System.out.println("Sum of a+b is "+sum);
}

void add(String s1, String s2)
{
String s = s1+s2;
System.out.println(s);
}
}
class overloadfunc{

public static void main(String args[])
{
Overload2 obj = new Overload2();

obj.add(4,19);

obj.add(4,17,11);

obj.add(1.5,21.5);

obj.add("Life at"," the speed of rail ");
}

}




Output will be:
Sum of a+b is 23
Sum of a+b+c is 32
Sum of a+b is 23.0
Life at the speed of rail


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. i installed the code in ecllipse,but i have one do
View Tutorial          By: vamsi at 2015-05-19 10:56:25

2. Hi all,
I'm getting this error on running

View Tutorial          By: shreya.g at 2008-06-23 00:13:52

3. very easy to understand ... a quite a good example
View Tutorial          By: Dinesh at 2012-09-22 18:19:45

4. the code works fine. you just need to create a mai
View Tutorial          By: Nabil at 2011-08-09 11:11:03

5. I did not understand it. please give one example e
View Tutorial          By: farhaan at 2008-03-20 12:06:11

6. I want to redirect from a servlet page to another
View Tutorial          By: dinesh at 2014-10-20 16:44:26

7. This is very useful for beginners.
I want f

View Tutorial          By: shankar at 2013-02-04 13:28:16

8. Whenever i run this program, it terminates immedia
View Tutorial          By: Salman at 2015-03-26 08:23:32

9. As soon as I added common-logging-1.1.1.jar My all
View Tutorial          By: shrawan kumar at 2011-10-30 12:06:50

10. finally! tnx google for taking me here :) my probl
View Tutorial          By: dorinn at 2009-04-02 10:32:40