Get the class from an object in Java

Description

The following code shows how to get the class from an object.

Example


/*from  ww  w  .j av a2  s. co m*/
public class Main {
  public static void main(String[] argv) throws Exception {
    Object object = new String();
    // By way of an object
    Class cls = object.getClass();
    System.out.println(cls);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy