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

Why parsing is done?

500


What is a class instance variable?

614


What is the meaning of find and replace?

522


Can a static class implement an interface?

547


Why do we need hashmap in java?

554






What is string and its types?

607


Can we overload the methods by making them static?

500


What is the functionality of the stub?

567


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

527


What is java abstraction with example?

550


What is byte data type?

546


What are 4 pillers of object orinted programming?

578


What is the super void?

454


What is a functional interface?

543


What is cr keyboard?

650