Casting class to interface in java -


why interface allow classes?

for example have 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 failed in run time      } } 

i know why failed in runtime because c1 class not implements i1 interface. if class c1 implements i1 above code work successfully.

can explain why interface allow class casting?

there a

class c2 extends c1 implements i1 { ... } 

an object of class assigned o1 , cast ok @ runtime.


Comments

Popular posts from this blog

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -