Advantages of Inheritance in java.

Answer Posted / pari

Minimize the amount of duplicate code in an application

If duplicate code (variable and methods) exists in two related classes, we can refactored that hierarchy by moving that common code up to the common superclass.

Better organization of code

Moving of common code to superclass results in better organization of code.

Code more flexible change

Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass.

Where to use inheritance:

Before using inheritance first compare the relationship for the two classes. Use inheritance only if there is a parent child relationship is there.
A way to test the relationship is to ask a "is-a" question.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is java in layman terms?

722


What interface is extended by awt event listeners?

802


What do you understand by synchronization?

784


Can we assign integer value to char in java?

702


What is a bufferedreader?

731


Name some OOPS Concepts in Java?

822


What are dot operator queries?

846


What does math floor () do?

726


Can we overload the constructors?

744


Why do we use variables?

693


What is return keyword in java?

796


define the terminology association.

866


Does set allows null in java?

701


How do I get a substring?

722


Is list ordered in java?

765