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
  • 267,707
  • 33
  • 569
  • 680
Jinu P C
  • 3,146
  • 1
  • 20
  • 29

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
  • 525,659
  • 79
  • 751
  • 1,130