I know that an interface is like a 100% pure abstract class. So, it can\'t have method implementation in it. But, I saw a strange code. Can anyone explain it?
For java version 7 or below, similar functionally you can achieve using nested class declared within interface body. and this nested class implements outer interface.
interface I1{
public void doSmth();
class DefaultRealizationClass implements I1{
@Override
public void doSmth() {
System.out.println("default realization");
}
}
}
class MyClass implements I1{
@Override
public void doSmth() {
new I1.DefaultRealizationClass().doSmth();
}
}
Therefore default implementation encapsulated within interface.