What is difference between overloading and overriding?
Answer Posted / javamasque
Overloading: As more than one methods are defined with in same class with same name but have any one of the below differences is called method overloading. It is also call static / compile time polymorphism.
1. Input parameter data type should be different.
2. Number of input parameters should be different.
There are two types of overloading as below
1. Constructor overloading.
2. Method overloading (instance / class)
Note: Overloading is not considered on below things
1. Return type (different type)
2. Access modifier ( broader / narrow)
3. Sequence of input parameters.
4. Different exceptions (new / broader)
Overriding: As a method in parent class is defined with exact same signature in one of its child class is call method overriding. It is called dynamic or runtime polymorphism. We have to consider below things while method overriding.
1. The visibility can be broader but can’t be narrower.
2. The exception can be specific but can’t be generic for checked exception.
3. The override method can throw any or new unchecked exception.
4. The return type can be narrower but can’t be broader.
5. The override method can’t be static / final / private.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is class and object in java?
What are the two types of streams offered by java 8?
Explain about join() method?
Can a lock be acquired on a class in java programming?
Where pragma is used?
Define jre i.e. Java runtime environment?
Can you make a constructor final?
What are autoboxing and unboxing? When does it occur?
Can we use a default constructor of a class even if an explicit constructor is defined?
What are the various access specifiers in java?
Explain about core java?
can rmi and corba based applications interact ?
Is there a way to increase the size of an array after its declaration?
How do you initialize an arraylist in java?
How are variables stored?