• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

residence of static variable

 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where do the static variables live in heap? inside instance variable or somewhere else?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The Java VM specification doesn't say specifically, so they could be anywhere. Why does it matter to you?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly not inside an instance variable. The thing you need to remember is this:

For static member variables, there is only 1 copy of the variable for the whole class. All instances of the class share the same variable.

For non-static (= instance) member variables, there is 1 copy of the variable for every instance of the class. Each instance has its own copy of the variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic