As we all know, there are only single-inheritance programming languages in the Java object-oriented language, and you might say that it is possible to achieve multi-inheritance by implementing multiple interfaces in a flexible way. Yes, you are right, but this is not the article to mention the content of this article is to talk about the real existence of Java in the multi-inheritance structure, nonsense said, let's go into the subject.
In fact, speaking of inheritance, everyone's first impression is certainly the inheritance of the class, as far as Java is concerned, the inheritance of the class is indeed a single inheritance, in this regard, undoubtedly, Java syntax and compiler will this point of the dead, suppose you try to let a class through the extends keyword inherits more than one parent class , compilation must pass.
The multi-inheritance that is said here is the multiple inheritance of the interface, and we know that when the class implements the interface, it uses the Implements keyword to implement multiple interfaces. An important feature of extensibility Java, if we want to extend the existing multiple interfaces, because it is not the implementation of the interface, we can not use the Implements keyword, then what to do, then you can only use the extends keyword. Here's a look at the code:
package com.lib.ThinkInJava.mutilExtends; public interface lethal {void Kill ();} package com.lib.ThinkInJava.mutilExtends; public interface monster {void Destroy ();} package com.lib.ThinkInJava.mutilExtends; public interface vampire extends Monster, lethal {void Drinkblood ();}
Vampire interface inherits the Monster,lethal two interfaces, and uses the keyword extends, in the compiler also does not have the error, is not very interesting, this is the Java multi-inheritance.
Note: Multiple inheritance in Java applies only to interfaces, classes do not inherit more, only single inheritance
Java Multiple inheritance