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

Where pragma is used?

602


What do you mean by append?

537


What are conditionals and its types?

592


1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?

3793


What are the differences between the constructors and methods?

582






Can we extend private class in java?

551


Is integer passed by reference in java?

570


Can we convert stringbuffer to string?

566


Write an algorithm for quick sort?

617


Is boolean a wrapper class in java?

602


What is mean by exception?

552


Explain what are final variable in java?

578


Is there any difference between synchronized methods and synchronized statements?

586


What is executor memory?

523


How do you change an int to a string?

547