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
Can java list contain duplicates?
Explain the significance of class loaders in bootstrap?
EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.
What is mean by collections in java?
What is the purpose class.forname method?
What are sets in java?
What is stringjoiner ?
Can I extend singleton class in java?
what is an objects lock and which objects have locks? : Java thread
What is serial version uid and its importance in java?
What is the difference between Error, defect,fault, failure and mistake?
What is the use of http-tunneling in rmi?
How is the marker interface used in Java?
How big is a gigabyte?
What is lifetime variable?