• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
Online Java Training-Online Java Tutor-Private Java Classes

Online Java Training-Online Java Tutor-Private Java Classes

Personal Online Java Training through Skype

  • Home
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • Contact Us

Multiple Inheritance in Java is not supported

For making Java language simple and avoid complexities present in earlier languages like c++, the founder of java(James Gosling) decided that java shouldn’t support Multiple Inheritance.

In a white paper titled “Java: an Overview” James Gosling gives an idea on why multiple inheritance is not supported in Java.

Gosling on omission of Multiple Inheritance in Java

“JAVA omits many rarely used, poorly understood, confusing features of C++ that in our experience bring more grief than benefit. This primarily consists of operator overloading (although it does have method overloading), multiple inheritance, and extensive automatic coercions.”

Ambugity problem due to Multiple Inheritance

If we try to do multiple inheritance in java we will come across an ambiguity problem. We will discuss about it below using an example.

Multiple Inheritance in Java is Not Supported

We have a super class A having a function called fun().
Two subclasses B and C extend class A providing their own implementation of fun() function.

Assume class D inherits from class B and class C.
If we create an object of class D and try to access function fun() guess what will happen.
i.e D obj=new D(); obj.fun();

This will lead to ambiguity problem. Because it’s difficult for java to decide which version of fun() function to execute, fun() of class B or fun() of class C. The above problem is also referred as diamond problem.

In c++ we have multiple inheritance and the problem is resolved using scope resolution operator. But java founders wanted to keep java simple and avoid complexities. Concepts like pointers, operator overloading are also avoided in java language for the same reason.

Multiple Inheritance in Java is not much required

Extending from two different classes having different implementations of a function is not much required in real world.

Filed Under: Java

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Mr Chinmay

Chinmay Patel

Phone & Whatsapp +919853166385
[email protected]
Skype id: p.chinmay

Recent Posts

  • How to Learn Java in One day ? | JavaTutorOnline
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse
  • How to learn Java Programming Language the Best way ? | JavaTutorOnline
  • Recursion in Java Example Program | Understanding Java Recursion
  • Important Core Java Interview Questions and Answers
  • How to Create Threads in Java | Multithreading in Java | JavaTutorOnline
  • Why Multiple Inheritance in Java not supported?
  • A Simple Spring Mvc Hello World Example | Spring Mvc Tutorial
  • How to become a good Teacher |Ideal Teacher | Perfect Teacher
  • OGNL in Struts 2 Tutorial | JavaTutorOnline
Copyright © 2022 JavaTutorOnline