Distinguish method overloading and method overriding
Answer Posted / umanath
Method overloading is compile time polymorphism and method
overriding is Runtime polymorphism.
Method overloading is having same name and different
parameters and different return type also. But same type and
same no:of parameters but different return type is not allowed.
Error while compile: type methodname(type name) is already
defined in classname.
Method overriding same name with same parameters and having
same return type in different class while inheritance is
applied.
Try this following program: this will throw a error while
compiling.....
class OverloadDemo {
int test(int x) {
return x*x;
}
long test(int a) {
long l = a*a*a;
return l;
}
double test(double a) {
return a*a;
}
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
How does queue work in java?
Explain about static nested classes in java?
What is a boolean flag in java?
Can we override the private methods?
How we can run a jar file through command prompt in java?
How does enum work in java?
What is function overriding and overloading in java?
What is scanner in java?
How to sort a collection of custom Objects in Java?
What is the function of character?
What is the arraylist in java?
What are the types of sockets in java?
How do you square a number?
Define an applet in java?
What is core java used for?