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


Please Help Members By Posting Answers For Below Questions

Why do we need data serialization?

536


What is a hashmap used for?

638


How to sort array of 0 and 1 in java?

539


What is use of static in java?

515


What are the 7 types of characters?

558






Does java linked list allow duplicates?

544


How to create an interface?

623


What happens if an exception is throws from an object's constructor?

621


What are methods in java?

530


What is a substitution variable?

554


What is array sorting in java?

543


Explain the use of sublass in a java program?

592


What is the basic concept of java?

527


How can we make a class singleton?

570


What are accessor methods in java?

546