group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
254 Members
Join this group to post and comment.
Archana Priyadarshini
Archana Priyadarshini
Computer Science
28 Jan 2019

Limitation 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.

The two classes (base and inherited class) get tightly coupled. This means one cannot be used independent of each other.

Java doesn't support multiple inheritance.

Shruthi Pillai
Shruthi Pillai
Information Technology
1mo ago

The inheritance relationship is a, tightly coupled relationship  . If we change code of parent class it will get affects to the all the child classes which is inheriting the parent code. 

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
1mo ago

1.The limitation of inheritance is that two classes are tightly coupled that is the classes (base class and super class)are dependent on each other.This means that if we change code of parent class it will affect to all the child classes which is inheriting/deriving the parent class and hence it cannot be independent of each other.

2.If the functionality of the base class is changed then the changes have to be done on the child class also.

3.If the methods in the super class are deleted then it is very difficult to maintain the functionality of the child class which has implemented the super class method.

4.It increases the time and efforts to.jump through different levels of the inheritance.If a given class has ten levels of abstraction above it then it will essentially take ten jumps to run through a function defined in each of those classes.

DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
1mo ago

Inheritance is overly reductive.  Inheritance is a tool, and it is very useful, but it's also very overused.  Inheritance should be used when the classes form a strict hierarchy, where subclasses are their parent classes in every sense of the word.

Inheritance is used as a convenient means of code reuse, and this is a big part of why it gets a bad reputation in some circles.  In such situation you should use composition over inheritance.

The answer for not using inheritance is that inheritance violates encapsulation.  In other words, by inheriting from a class you're coupling yourself with any number of potential implementation details of the parent, all of which are completely avoided by using composition instead.