Class object
See also: "in-depth understanding of the Java Virtual Machine JVM advanced features and best practices Version 2" => Chapter 7 virtual machine class loading mechanism
Once the class is loaded into memory, then regardless of the class Class object is obtained by the way, they are returned to the same point on the java heap address Class (for HotSpot zone method) reference.
package org.test.a;
class Cat{
static {
System.out.println("static cat");
}
}
public class Demo {
public static void main(String[] args) throws ClassNotFoundException {
Class c1 = Cat.class;
Class c2 = new Cat().getClass();
Class c3 = new Cat().getClass();
Class c4 = Class.forName("org.test.a.Cat");
System.out.println(c1 == c2);
System.out.println(c2 == c3);
System.out.println(c3 == c4);
}
}
Output:
static cat
true
true
true