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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -