This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about local variable

 
chun-ju Lin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,
a local variable is simply a variable within a method.
eg:
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.
ben
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello chun-ju Lin,

hope this helps
Davy
 
chun-ju Lin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the point,thank you for help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic