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


Please Help Members By Posting Answers For Below Questions

What is the longest unicode character?

695


What is bytecode verifier?

507


What are the advantages of java inner classes?

563


What is initial size of arraylist in java?

538


What is java in simple terms?

566






Why java is a platform independent? Explain

536


What is array sorting in java?

557


Define interface in java?

609


What is constructor and its types?

541


Do I need java on my computer?

528


Can we override compareto method?

508


What do you mean by a JVM?

571


Which access specifier can be used with class ?

537


How do you add an arraylist to an array in java?

511


What is string [] java?

530