File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the variable in static method

 
lee dong
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!
I want to konw is the variable in static method static too?
like that:


-------------------
How the static method and the variable in the static method orgnized in memory?

many thx!
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static method or variable belongs to a class (instead of an instance of
an object), and the static variables get initialized when the classes are
loaded.

a)
No, i is not a static var. It's a local variable.

b)
They are located (edit on the stack

/Svend Rost
[ January 30, 2006: Message edited by: Svend Rost ]
 
lee dong
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Svend Rost:

They are located in the heap area.


No, local variables always are located on the stack.
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


No, local variables always are located on the stack.


Sorry - I was to careless to look it up.. Thanks for correcting me.

/Svend Rost
 
Chandrasekhar Mangipudi
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods which belongs to static and non-static can have Local variables. so "i" is a local variable.It needs to be intialized before using the variable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic