what is overloading in java?
Answer Posted / binod kumar
IF WE HAVE SAME METHOD NAME WITH DIFFERENT TYPES OF PARAMETERS THEN IT IS KNOWN AS METHOD OVERLOADING.
EXAMPLE----------->
class A
{
void sum(int a,int b)
{
int s=a+b;
System.out.println("Sum of a+b is:" +s);
}
void sum(int x,int y,int z)
{
int s2=x+y+z;
System.out.println("Sum of x+y+z is:" +s2);
}
}
class ovrloading
{
public static void main(String str[])
{
A a=new A();
a.sum(10,20);
a.sum(10,20,30);
}
}
IN GIVEN EXAMPLE WE HAVE SUM METHOD WITH DIFF PARAMETERS.
OUTOUT WILL BE------->
Sum of a+b is: 30
Sum of x+y+z is: 60
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which list does not allow duplicates in java?
Is there any way to skip finally block of exception even if some exception occurs in the exception block?
What is stack example?
What are exception handling keywords in java?
How we can run a jar file through command prompt in java?
What is predicate in java?
What is sortedset in java?
Can we have try without catch block?
What is a buffer in computer?
What is the largest number a double can hold?
Explain the protected field modifier?
Can we convert integer to string in java?
What is scope & storage allocation of global and extern variables? Explain with an example
Is java an open source?
explain autoboxing in java?