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


Please Help Members By Posting Answers For Below Questions

Is class is a data type?

566


when should you use stringbuilder class in a program?

516


How will you reverse a singly-link list?

587


What do heavy weight components mean in java programming?

515


Can we inherit a class with private constructor?

562






Explain about field hiding in java?

519


What do you understand by looping in java? Explain the different types of loops.

553


How java enabled high performance?

578


What classes of exceptions may be caught by a catch clause in java programming?

693


What is the benefit of singleton pattern?

515


What is the difference between yielding and sleeping in java programming?

578


How do you convert string to int in java?

548


Is an array a vector?

544


Does substring start with 0?

548


What is abstract class constructor called?

557