The reason behind this is to prevent ambiguity in JAVA. Consider a case where class B extends class A and Class C and both class A and C have the same method display(). Now java compiler cannot decide, which display method it should inherit. To prevent such situations, multiple inheritances is not allowed in java.
Implementing multiple interfaces in java
interface Flyable {
void fly();
}
interface Eatable {
void eat();
}
// Bird class will implement both interfaces
class Bird implements Flyable, Eatable {
public void fly() {
System.out.println("Bird flying");
}
public void eat() {
System.out.println("Bird eats");
}
}
/*
* Test multiple interfaces example
*/
public class Sample {
public static void main(String[] args) {
Bird b = new Bird();
b.eat();
b.fly();
}
}