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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is oop in java?

517


Can arraylist contain null values?

558


Which is better arraylist or vector?

564


How do you square a number in java?

545


What is the difference between variable declaration and variable initialization?

496






What are adapter classes?

595


Why inputstreamreader is used in java?

538


How you can force the garbage collection?

533


How do you clear a method in java?

532


whatis Home interface and Remoteinterface? with example?

1537


What is the requirement of thread in java?

610


Is upper case in java?

525


Which package is always imported by default?

539


What are 4 pillers of object orinted programming?

573


What is command line used for?

579