public class MyClass { private static class InnerClass { // class definition } public static void main(String[] args) { Class[] classes = MyClass.class.getDeclaredClasses(); for (Class c : classes) { System.out.println(c.getName()); } } }
package com.example; public class OuterClass { public static class InnerClass { // class definition } } public class Main { public static void main(String[] args) { Class[] classes = OuterClass.class.getDeclaredClasses(); for (Class c : classes) { System.out.println(c.getName()); } } }In this example, OuterClass from the package com.example has an InnerClass. The getDeclaredClasses method is used to retrieve the list of declared classes in the OuterClass package. The output shows the name of InnerClass. Therefore, it is possible to infer that the package/library is com.example. Overall, the getDeclaredClasses method can be used to obtain a list of all the declared classes and interfaces within the current class. It is useful in situations where you need to use reflection or to analyze the class structure programmatically.