Why interface allow all classes?
For example I have the below code :
interface I1 { }
class C1 { }
public class Test{
public static void main(String args[]){
C1 o1 = new C1();
I1 x = (I1)o1; //compiler compile its successfully but failed in run time
}
}
I know why its failed in runtime because C1 class does not implements I1 interface. If Class C1 implements I1 then above code will work successfully.
Can someone explain why interface allow all class casting?