CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Why Multiple Inheritance is not Supported in Java?

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Why Multiple Inheritance is not Supported in Java?

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: July 29, 2023 · 2 min read · 0 Comments
Share: in X
Why Multiple Inheritance is not Supported in Java?

Multiple inheritance is not supported in Java because it can lead to ambiguity. This is the problem of having two or more base classes with the same method or field. In this case, the compiler would not know which method or field to inherit, which could lead to errors.

For example, consider the following code:

class Parent1 {
  public void method1() {
    System.out.println("This is method1 from Parent1");
  }
}

class Parent2 {
  public void method1() {
    System.out.println("This is method1 from Parent2");
  }
}

class Child extends Parent1, Parent2 {
  // What method1 should be called here?
}

In this case, the Child class inherits two methods with the same name, method1(). The compiler would not know which method to inherit, so it would not be able to compile the code.

Then what is the solution to this problem?

There are a few ways to work around this problem in Java. One way is to use interfaces. An interface can contain a method signature, but it does not contain an implementation. This means that a class can implement multiple interfaces, and each interface can have a method with the same name. The class then has to provide an implementation for each method, so there is no ambiguity.

Another way to work around the problem of multiple inheritance is to use composition. Composition is the act of creating a new object by combining existing objects. In this case, the Child class could be created by composing the Parent1 and Parent2 classes. This would avoid the problem of multiple inheritance, because the Child class would not inherit any methods from Parent1 or Parent2 directly.

In general, multiple inheritance is not supported in Java because it can lead to ambiguity. However, there are a few ways to work around this problem, such as using interfaces or composition.

Following are some other reasons why multiple inheritance is not supported in Java:

  • It can make code more complex and difficult to understand.
  • It can lead to errors if the methods or fields from the base classes have conflicting implementations.

Related Posts:

  • Inheritance in Java: A Developer’s Guide to Code Reusability
  • Extends Keyword in Java: A Deep Dive into Inheritance
  • Top 10 Common Java Errors
  • Nested and Inner Class in Java
  • Recursion in Java
  • Interface in Java: Mastering Abstraction and…
Tags:javalanguage-fundamentals
Was this article helpful?
← Previous ArticleHow to Create Method in Java?
Next Article →Extends Keyword in Java: A Deep Dive into Inheritance

Recent Posts

  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap