Java Class.getDeclaredClasses()
Syntax
Class.getDeclaredClasses() has the following syntax.
public Class <?>[] getDeclaredClasses() throws SecurityException
Example
In the following code shows how to use Class.getDeclaredClasses() method.
// w w w .j a va 2s .c om
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.