Consider the sample code below
public class Test { public static void main(String args[]) { Test t = new Test(); Class c2 = Test.class; System.out.println(c2); } }
Test.class
statically evaluates and returns the time of a class object. If you look at the syntax of Test.class
, it looks like a class of the variable type java.lang.Class and is static and public
. My question is where is this variable defined? It is not in the Test class (because I do not declare it) nor in the java.lang.Object class.
I saw a similar method public final native Class<?> getClass();
. This is present in java.lang.Object
and is a native java method
. This method returns the runtime class of the object.
So my question is where is this variable public and static class defined? (Please correct me if I am wrong). Is this again some kind of own implementation? This is set at compile time and does not statically require instantiating a class. So, even if this is some kind of built-in implementation, is it initialized with the registerNatives()
method in java.lang.Object?
source share