| 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
|
 |
 |
|
|
subject: Static Keyword
|
|
|