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
What is the history of java?
What is a pattern what is an anti pattern?
Can bool be null?
who can i handle multiple client in RMI
Who found java?
What are the main differences between the java platform and other platforms?
I want to persist data of objects for later use. What’s the best approach to do so?
How do I write a self declaration?
What is polymorphism in java? What are the kinds of polymorphism?
Can we override singleton class?
What is a void method?
How to compare strings in java?
What does method mean?
Given a singly linked list, determine whether it contains a loop or not without using temporary space?
Why are there no global variables in java?