Monday, 14 March 2016

How to create method overloading in java


Method overloading:-When multiple methods in a class with same name but different parameters is called a method overloading.

class Over{
void sum(int a,int b){
System.out.println(a+b);
}
void sum(double a,double b){
System.out.println(a+b);
}
public static void main(String args[]){
Over obj=new Over();
obj.sum(11.5,11.5);
obj.sum(5,5);
}
}

OUTPUT:-
C:\Users\Satyendra\Desktop>javac 1.java
C:\Users\Satyendra\Desktop>java Over
23.0

10

No comments:

Post a Comment