• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Keyword

 
bharadwaz reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody please explain the static keyword with a suitable example?
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bharadwaz,

Welcome to javaranch!!!
static is quite a huge topic to explain in one post. If you have some specific problem, ask that question here with your code snippet.
show us that you have put some effort into it. Surely, we'll try to help.

Still, to explain it in short.
static keyword is used for the whole class in general, not for a specific instance of the class.
So, when you declare an instance variable or method as static, it means that all the instances of the class will have the same copy.

Here if you create two objects of the class

Both these objects will have their own version of instanceVar variable, but both will have the same version of staticVar variable
The same goes for the methods too....

HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic