In Java, a class cannot extend multiple classes. Therefore the following is illegal -
public class extends Animal, Mammal{}
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!