Let\'s say we have a class:
class Class1
{
int i = 1;
}
and we have a variable:
Class1 ob1 = new Class1();
This is one of the scheme in which the JVM can store the information of the class for the check at runtime using instanceOf
.
Every Java virtual machine must have the capability to determine information about its class, given only a reference to an object. This is needed for many reasons, including type-safe casting and the instanceof operator.
This is one way in which a Java virtual machine implementation could associate class information with the instance data for an object. In this figure, a native pointer to a data structure containing class information is stored along with the instance variables for an object. The details in which the various ways a JVM could connect an object's data with its class information are beyond the scope of this article. The important thing to understand here is that class information will in some way be associated with the instance data of objects, and that the instance data includes fields for an object's class and all its superclasses.
Artima post on Object initialization
So when you do instanceOf
check the information about the class is accessed via this pointer. But again do keep in mind that the exact implementation about the storage of class information may be implementation specific.