0

Where is class static field is declared and how this field is associated with every classes?

System.out.pritnln(String.class);
System.out.pritnln(Student.class);

output:

class java.lang.String
class Student
Oliver Charlesworth
  • 260,367
  • 30
  • 546
  • 667
Jinu P C
  • 2,756
  • 18
  • 27

1 Answers1

0

It depends on the implementation of the VM, but if you do a heap dump of the Hotspot JVM you can see a special object for each class which holds the static fields.

You can access them dynamically at runtime by using reflection.

Peter Lawrey
  • 513,304
  • 74
  • 731
  • 1,106