aspose file tools*
The moose likes Beginning Java and the fly likes Static Keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Keyword" Watch "Static Keyword" New topic
Author

Static Keyword

bharadwaz reddy
Greenhorn

Joined: Jul 08, 2009
Posts: 4
Can somebody please explain the static keyword with a suitable example?
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
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


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Keyword