Online Java Compiler By
JavaTpoint.com
public class ClassgetDeclaredclassesExample2 { public static void main(String[] args) throws Exception { Class clsnm = Class.forName("AnotherClass"); Class[] classestot = clsnm.getDeclaredClasses(); for (int i = 0; i < classestot.length; i++) { System.out.println("Class " + (i+1)+ " = "+ classestot[i].getName()); } } } class AnotherClass { public class InrClass1 { public InrClass1() { System.out.println("Inside Inner Class1"); } } public class InrClass2 { public InrClass2() { System.out.println("Inside Inner Class2"); } } private class InnerPrivateClass { public InnerPrivateClass() { System.out.println("Inner Private Class"); } } }
Output