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.

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;
System.out.println("Addition of two number is: " + i3);

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

public static void main(String args[])
OverloadingTest obj=new OverloadingTest();
obj.add("Test"," Best");

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