Class.getDeclaredClasses() has the following syntax.
public Class <?>[] getDeclaredClasses() throws SecurityException
In the following code shows how to use Class.getDeclaredClasses() method.
/*from w w w. ja v a 2 s . co m*/ public class Main { public static void main(String[] args) throws Exception { Class cls = Class.forName("MyClass"); Class[] classes = cls.getDeclaredClasses(); for (int i = 0; i < classes.length; i++) { System.out.println("Class = " + classes[i].getName()); } } } class MyClass { public class InnerClass1 { public InnerClass1() { System.out.println("Inner Class1"); } } public class InnerClass2 { public InnerClass2() { System.out.println("Inner Class2"); } } private class InnerPrivateClass { public InnerPrivateClass() { System.out.println("Inner Private Class"); } } }
The code above generates the following result.