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
Can a abstract class be declared final?
What is a functional interface?
What is the role of garbage collector in java?
Can you extend singleton class?
Can I uninstall java?
What are the important features of Java 10 release?
how to create daemon thread in java?
What is a method header?
How to declare an arraylist in java?
What is final access modifier in java?
How do you sort arraylist in descending order?
What is a constructor overloading in java?
Which oo concept is achieved by using overloading and overriding?
How can you read content from file in java?
Which class is the superclass for all the classes?