Java Data Type Tutorial - Java Object.getClass()








Syntax

Object.getClass() has the following syntax.

public final Class <?> getClass()

Example

In the following code shows how to use Object.getClass() method.

//from w  ww  .  j  ava2s  .  c o  m
import java.util.GregorianCalendar;

public class Main {

   public static void main(String[] args) {

      // create a new Main object
      GregorianCalendar cal = new GregorianCalendar();

      // print the class of cal
      System.out.println(cal.getClass());

   }
}

The code above generates the following result.