Code: Select all
interface Measurement{
public default int getLength(){ // <==== (1)
return 0;
}
public static int getBreadth(){
return 0;
}
}
interface Size extends Measurement{
public static final int UNIT = 100;
public static int getLength(){ // <==== (2)
return 10;
}
}
getLength method in Size is invalid because a default method cannot be overridden by a static method (or vice versa).
as expected. When you said a default method cannot be overridden by a static method (or vice versa), that means a static method CANNOT be overridden by a default method as well if I can borrow your own words. I tried it and it compiled without any issue.error: getLength() in Size clashes with getLength() in Measurement
public static int getLength(){
^
overriding method is static
1 error
I've also tried to override a static method with an abstract method and this too compiles and ends without any issue.
What did you exactly meant when you said vice versa?