Given a class
public class A {
public static int classVal;
}
During run-time, does the type A
become a reference to a class Object
?
public static void main(String[] args) {
A a = new A();
A.classVal = 100;
A.classVal = 200;
}
if A.classVal
is a reference to static Class variable, then is A
a reference to an Object that represents the class?
does a.getClass()
refer to the same object as A
?
To clarify
if A.classVal
is a reference, and A
is nothing more than a name, does a class just become part of a lookup table that uses the class name as a key? I am trying to understand what happens to a class at run-time.
No, A
isn't a reference at all. It's just the class name. A
is not an expression in its own right - it doesn't have a value. It can only be part of another expression (like A.classVal
or new A()
).
See more on this question at Stackoverflow