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
What are generic methods?
What are examples of modifiers?
List the features of java programming language.
How to calculate the length of a singly linked list in java?
does java support pointers?
Where are variables stored?
Is an integer an object?
What is an exception? difference between Checked and Unchecked exception in Java
What does exclamation mean in java?
What is the use of conditional statement?
Whats the difference between notify() and notifyall()?
What is the difference between menuitem and checkboxmenu item?
Explain scope or life time of local variables in java?
Explain the Propertie sof class?
What is java util?