Can somebody please explain the static keyword with a suitable example?
Joined: Sep 03, 2007
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....