DEVFYI - Developer Resource - FYI

What are the drawbacks of inheritance?

Java Interview Questions and Answers (part 1)


(Continued from previous question...)

144. What are the drawbacks of inheritance?

Since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation. In addition, the inheritance may make peers hardly understand your code if they don't know how your super-class acts and add learning curve to the process of development.
Usually, when you want to use a functionality of a class, you may use subclass to inherit such function or use an instance of this class in your class. Which is better, depends on your specification.

(Continued on next question...)

Other Interview Questions