Full width home advertisement

Post Page Advertisement [Top]

A class have two or more method with same name but different parameter. This is called overloading method in Java.
Example:

class OverloadingTest
{
public void add(String s1, String s2)
{
String s3=s1 + s2;
System.out.println("Addition of two string is: " + s3);
}

public void add(int i1, int i2)
{

int i3;
i3=i1+i2;
System.out.println("Addition of two number is: " + i3);
}

public void add(int i1, int i2,int i3)
{
int i4;
i4=i1+i2+i3;
System.out.println("Addition of three number is: " + i4);
}

public static void main(String args[])
{
OverloadingTest obj=new OverloadingTest();
obj.add("Test"," Best");
obj.add(3,4);
obj.add(2,5,4);
}
}


Output :

Addition of two string is: Test Best
Addition of two number is: 7
Addition of three number is: 11

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib