Online Java Compiler By
JavaTpoint.com
import java.lang.*; public class ClassgetClassesExample1 { public static void main(String[] args) { try { Class clsobj = Class.forName("ClassgetClassesExample1"); Class[] totcls = clsobj.getClasses(); for (int i = 0; i < totcls.length; i++) { System.out.println("Class " +i+ " = " + totcls[i].getName()); } } catch (ClassNotFoundException e) { System.out.println(e.toString()); //coverting exception object to string and printing it } } public class subclass1 { public subclass1() { System.out.println("subclass Class1"); } } public class subclass2 { public subclass2() { System.out.println("subclass2 Class2"); } } private class PrivatesubClass { public PrivatesubClass() { System.out.println("subclass Private Class"); } } }
Output