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
Where pragma is used?
What do you mean by append?
What are conditionals and its types?
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?
What are the differences between the constructors and methods?
Can we extend private class in java?
Is integer passed by reference in java?
Can we convert stringbuffer to string?
Write an algorithm for quick sort?
Is boolean a wrapper class in java?
What is mean by exception?
Explain what are final variable in java?
Is there any difference between synchronized methods and synchronized statements?
What is executor memory?
How do you change an int to a string?