Java Class.getClasses()

Syntax

Class.getClasses() has the following syntax.

public Class <?>[] getClasses()

Example

In the following code shows how to use Class.getClasses() method.


/*ww  w.  j  av  a  2s. c  o m*/
public class Main {

  public static void main(String[] args) throws Exception {

    Class cls = Class.forName("java.lang.String");

    Class[] classes = cls.getClasses();
    for (int i = 0; i < classes.length; i++) {
      System.out.println("Class found = " + 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");
    }
  }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable