Thursday 25 March 2021

Java interface - Diamond Problem

 public interface InterfaceEx {


default void name(){} //default method
static void name6(){}
}

interface InterfaceEx1{
default void name(){} // default method
static void name6(){}
}

//If a class is implementing 2 or more interfaces, with same method signature, compiler enforces class to Override that method.
//This is how diamond problem is resolved.
class ClassEx implements InterfaceEx, InterfaceEx1{ //

@Override
public void name() {

}
}

No comments:

Post a Comment