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 the maximum length of a url?
How to display all the prime numbers between 1 and n (n is the number, get the input from user)
Can we write multiple catch blocks under single try block?
What is identifier in java?
Whats the difference between notify() and notifyall()?
How can you avoid serialization in child class if the base class is implementing the serializable interface?
What is a stack class in java ?
How large is a boolean?
What is a generic type?
What is the use of join method?
What is the difference between an inner class and a sub-class?
what is predefined function in java?
What is the meaning of flag day?
Is java developer a good career?
Can a method be static?