In this example on java website's tutorial page. Two interfaces define the same default method startEngine()
. A class FlyingCar
implements both interfaces and must override startEngine()
because of the obvious conflict.
public interface OperateCar {
// ...
default public int startEngine(EncryptedKey key) {
// Implementation
}
}
public interface FlyCar {
// ...
default public int startEngine(EncryptedKey key) {
// Implementation
}
}
public class FlyingCar implements OperateCar, FlyCar {
// ...
public int startEngine(EncryptedKey key) {
FlyCar.super.startEngine(key);
OperateCar.super.startEngine(key);
}
}
I don't understand why, from FlyingCar
, super
is used to refer to both versions of startEngine()
in OperateCar
and FlyCar
interfaces. As I understand it, startEngine()
was not defined in any super class, therefore shouldn't be referred as resident in one. I also do not see any relationship between super
and the two interfaces as implemented in FlyingCar