Two Laptop Bag
The moose likes Beginning Java and the fly likes about local variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about local variable" Watch "about local variable" New topic

about local variable

chun-ju Lin

Joined: Feb 18, 2004
Posts: 6
Could someone tell me the difference between instance ,static and local variable?I only know that static variable comes with class and instance variable comes with object,but how about local variable?In what situation should I use local variable?
Sorry ,my English is very poor.
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
a local variable is simply a variable within a method.
public void myMethod()
int n = 2;
//do something
so in this case the integer n is a local variable. You have to be careful with local variables, since they get deallocated from memory (sometime) after the method is executed. This means you can use local variables only within the method where they occur.
hope that helps.
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hello chun-ju Lin,

hope this helps

How simple does it have to be???
chun-ju Lin

Joined: Feb 18, 2004
Posts: 6
I get the point,thank you for help.
I agree. Here's the link:
subject: about local variable
It's not a secret anymore!