EXAMPLE OF METHOD OVERLOAING
CLASS Overloading
{ public void sum(int a,int b)
{ System.out.println("sum of two integers is="+(a+b));
}
public void sum(float a,float b)
{
System.out.println("sum of two float value is="+(a+b));
}
public static void main(String arg[])
{ Overloading k=new Overloading();
k.sum(3,4);
k.sum(4.3,8.4);
}
}
The method over loading in java mean we just made more than one method in program of same name and it will execute according to input given or according to condition as show in above example there two method of same name and according to input they both will execute.
OUTPUT OF ABOVE PROGRAM
sum of two integers is=7
sum of two float value is=12.7
PLEASE COMMENT BELOW IF YOU HAVE ANY QUERY
No comments:
Post a Comment