• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

asking about static n non static memory difference

 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
its been a long time n have a question again.i want to know about the memory difference betwen a static n a non-static variable.how much memory they alocate n exactly wat difference is made when a static or a non static vriable is used.i mean what is the criteria for using a static or a non static variables.i hope that u ppl will reply me asap.
take care
with regards
kumar abhay
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a variable that should be shared by all instances of a class, then declare it static, since only one static variable exists for the entire class and sunclasses. Since only one static variable exists it takes less memory than instance variables which exixt for each instance of the class.

Bosun
------------------
Bosun
SCJP for the Java� 2 Platform
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know about the memory difference betwen a static and a non-static variable, how much memory they allocate and what is the criteria for using a static or a non static variable.

How much memory each variable allocates is independent of whether the variable is static or not.
 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
thanks alot it helped me alot.
take care
with regards
kumar abhay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic