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
Why parsing is done?
What is a class instance variable?
What is the meaning of find and replace?
Can a static class implement an interface?
Why do we need hashmap in java?
What is string and its types?
Can we overload the methods by making them static?
What is the functionality of the stub?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
What is java abstraction with example?
What is byte data type?
What are 4 pillers of object orinted programming?
What is the super void?
What is a functional interface?
What is cr keyboard?