Java – Size of reference of an class in JAVA

classjavareferencesize

What is the size of reference of a class in Java? Is it constant for a particular JVM and OS irrespective of the class for which the reference is made.


Class A
Class B
Class C

A a;
B b;
C c;

Are the size of a, b and c the same irrespective of the size of A, B and C classes?

Best Answer

Yes, all references are "pointers" to Objects or indirect "pointers to pointers" to Objects. Their actual in memory size is an implementation detail of the JVM but you can be sure that they are equal in size for different classes.