Try catch | Sololearn: Learn to code for FREE!


Try catch

Class simple{ } Interface my { } Class test { public static void main(String [ ] args){ Try{ Class c =class.forName(“simple”); System.out.println(c.isInterface()); Class c2=class.forName(“my”); System.out.println(c2.isInterface( )); } Catch(exception e) { System.out.println(e);} }} Iam getting Output : false true Which statement is flase and which statement is true ?How can explain anyone....

5/14/2020 4:17:21 PM

Haritha Vuppula

3 Answers

New Answer


Output tells you 1st one is false, 2nd one is true....! Yes. c.isInterface() is false because c is referencing to "Simple " which is class not interface. c2.isInterface() is true, because c2 is assigned to "my", which is interface...


c2 is assigned as a refference to "my" interface. So it can store information related to " my" literal which is a name of interface.. A class is compatible type to interface so it can store information about inferface, like a class... You can read about Class class for more information.


tqsm Jayakrishna🇮🇳 but obj c2 is created for class