File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Local Variable vs. Member Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Local Variable vs. Member Variable " Watch "Local Variable vs. Member Variable " New topic
Author

Local Variable vs. Member Variable

Marius BONG
Greenhorn

Joined: Dec 16, 2001
Posts: 13
what is the different between those two variable ? i got confused when i read some books which tell me different thing.
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Local variables have scope limited to the enclosing braces (ie. {,})
whereas member variables are always associated with an instance of a class and their scope is same as the scope of the enclosing object
e.g
class SomeClass
{
int x; // <- this is a member variable
void foo()
{
int y; // <- this is a local variable for function foo
}
}
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Member variables are part of the object that is build on the heap. So they are fairly permanent things, at least as permanent as the object is.
Local variables are convenience items used by Methods to do what they need to do. They are kept in the stack that relates to the method being executed. When the method is over - they die.
Static variables are part of the class definition, and are kept in the classfile. When a class is first referenced in any manner the classfile is built, along with the static variables, and stays there until the class is unloaded - which for the most part is as long as the JVM is running.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Marius BONG
Greenhorn

Joined: Dec 16, 2001
Posts: 13
thanks a lot guys...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Local Variable vs. Member Variable
 
Similar Threads
polymorphism help...
More question ...
Alternative to SWITCH statement
Variable in Passivation
Static & Class Variables