Can two interfaces mutually extend each other? Why or why not?
Can two interfaces mutually extend each other? Why or why not?
short answer: No.
Two interfaces can not extend to each other, However an interface can extend multiple interfaces.
Why:
When an interface extends another interface, first one becomes child interface and the later becomes parent interface
in object oriented programming, parent interface doen't mean to inherit child interface methods, if parent interface extends child interface and vice versa, it throws error saying hierarachy of interfaces is inconsistent.
parent interface contains universal methods and child inteface have relatively specific methods.
Let's take an example for better understanding
public interface Animal {
public String animalName();
public void animalSound();
public short animalAge();
}
public interface Bird extends Animal {
public short flyingSpeed();
public int flyingAltitude();
public byte numberOfEggsLaid();
}
in the above example, Bird can extend Animal as all birds are animals and can have name, age, sound. Those are universal.
But Animal can't extends Bird. As It doesn't make sense for Dog to have flying speed, flying altitude, number of eggs it laid.
So that explains why two interfaces can't extend each other.