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 equlas() and hashcode() contract in java? Where does it used?
What is string [] args?
Explain about serializable interface in java?
What about instanceof operator in java?
Is minecraft 1.15 out?
what is nested class in java?
What is mean by encoding?
Why string is immutable or final in java
Difference between Linked list and Queue?
Is arraylist a class in java?
Is integer passed by reference in java?
What is a short in java?
how can you take care of mutual exclusion using java threads? : Java thread
What invokes a thread's run() method in java programming?
What super () does in java?