How multiple inheritance is implemented using interfaces in Java?

Java 8Object Oriented ProgrammingProgramming

Java does not support multiple inheritance. This means that a class cannot extend more than one class. Therefore, following is illegal −

Example

public class extends Animal, Mammal{}

However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritance.
The extends keyword is used once, and the parent interfaces are declared in a comma-separated list.
For example, if the Hockey interface extended both Sports and Event, it would be declared as −

Example

public interface Hockey extends Sports, Event
raja
Published on 09-Feb-2018 10:56:55
Advertisements