Online Java Compiler By
JavaTpoint.com
import java.lang.*; public class ClassgetDeclaredclassesExample1 { public static void main(String[] args) { try { Class clsnm = Class.forName("ClassgetDeclaredclassesExample1"); Class[] classespresent = clsnm.getDeclaredClasses(); for (int i = 0; i < classespresent.length; i++) { System.out.println("Class " + (i+1)+ " = "+ classespresent[i].getName()); } } catch (ClassNotFoundException e) { System.out.println(e.toString()); } } public class InClass1 { public InClass1() { System.out.println("Inner InClass1"); } } public class InClass2 { public InClass2() { System.out.println("Inner InClass2"); } } private class InPrvtClass { public InPrvtClass() { System.out.println("Inner Private Class3"); } } }
Output