What is method Overloading in the perspective of OOPS?
Answer Posted / amarnath88888
Two or more methods having same name but different
signatures in the same class or in super class, sub
class(inheritance) then, that method is said to be
overloaded method.
This process is known as method overloading.
Note: Signature of a method means
1) no. of parameters
2) type of the parameter
3) order of the parameters
And a method cant be said as overloaded method only with the
change of the return type alone.
For example,
1) //for no of parameters
void display(int a,int b,int c)
{
System.out.println("This is 3 arguments method");
}
void display(int a,int b)
{
System.out.println("This is 2 arguments method");
}
2) //for type of parameters
void display(int a,int b)
{
System.out.println("This is 2 int arguments method");
}
void display(float a,float b)
{
System.out.println("This is 2 float arguments method");
}
3) //for order of parameters
void display(int a,float b)
{
System.out.println("This is int,float argument method");
}
void display(float a,int b)
{
System.out.println("This is float,int argument method");
}
Note: // cant determine only with return type
void display(int a,int b)
{
System.out.println("This is 2 arguments method without
return type");
}
int display(int a,int b)// compile error here
{
System.out.println("This is 2 arguments method with return
type");
}
Is This Answer Correct ? | 5 Yes | 2 No |
Post New Answer View All Answers
What is immutable in java?
What does it mean that a class or member is final?
What is flush () in java?
Do I need java on my pc?
What is variable length arguments in java?
State the merge-sort principle and its time complexity.
What is unicode full form?
what do you mean by stream pipelining in java 8? Explain
How do you sort arrays in java?
How can you traverse a linked list in java?
Why does java have two ways to create child threads?
What is a method vs function?
What is the difference between && and & in java?
What is hashset in java?
What are the different types of multitasking?