Home > Java > javaTutorial > Why doesn't Java support multiple inheritance?

Why doesn't Java support multiple inheritance?

WBOY
Release: 2023-09-20 22:17:02
forward
947 people have browsed it

Why doesnt Java support multiple inheritance?

In Java, a class cannot extend multiple classes. Therefore the following is illegal -

Example

public class extends Animal, Mammal{}
Copy after login

However, a class can implement one or more interfaces, which helps Java get rid of the impossibility of multiple inheritance.

The reason for this is to prevent ambiguity.

Consider a situation where class B extends class A and class C, and both classes A and C have the same method display().

Now the java compiler cannot decide which display method it should inherit. To prevent this, multiple inheritance is not allowed in java.

The above is the detailed content of Why doesn't Java support multiple inheritance?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template