What is difference between overloading and overriding?

Answers were Sorted based on User's Feedback



What is difference between overloading and overriding?..

Answer / 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
2. Access modifier
3. Sequence of input parameters.
4. Different exceptions

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. Method overriding is still considered even if the override method in child class is differ as below from its parent method.
1. The visibility can be broader but can’t be narrower.
2. The exception can be specific but can’t be generic.
3. The return type can be narrower but can’t be broader.

Is This Answer Correct ?    6 Yes 0 No

What is difference between overloading and overriding?..

Answer / 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

More Core Java Interview Questions

What are features of java?

0 Answers  


How to display all the prime numbers between 1 and n (n is the number, get the input from user)

0 Answers  


What do you mean by data type?

0 Answers  


what is daemon thread and which method is used to create the daemon thread? : Java thread

0 Answers  


Is java developer a good career?

0 Answers  






What are the problems faced by java programmers who don't use layout managers?

0 Answers  


Is 0 a prime number?

0 Answers  


why we need this (1.object,2.class,3.data hiding,4.encapsulation,5.abstraction,6. polymorphism,7.inheritance)

2 Answers  


How do I start learning java?

0 Answers  


Difference between process and thread?

0 Answers   HP,


What is the purpose of a parameter?

0 Answers  


What is an exception? difference between Checked and Unchecked exception in Java

0 Answers   SkillGun Technologies,


Categories