what is overloading in java?
Answers were Sorted based on User's Feedback
Answer / saurabh
it is a example of overloading:-
class Overload {
void test(int a) {
System.out.println("a: " + a);
}
void test(int a, int b) {
System.out.println("a and b: " + a + "," + b);
}
double test(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
class MethodOverloading {
public static void main(String args[]) {
Overload overload = new Overload();
double result;
overload.test(10);
overload.test(10, 20);
result = overload.test(5.5);
System.out.println("Result : " + result);
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / 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 |
What is a Presistent Object?
0 Answers InfoAxon Technologies,
What is stringjoiner ?
What is temp in java?
What is the list interface in java programming?
Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..
What is toarray method in java?
Java support call by reference (pass by reference) ?
What is difference between wait and notify in java?
Can a function return a function?
What is a class variable?
Which one will take more memory: an int or integer?
To what value is a variable of the Boolean type automatically initialized?