Static converts an instance variable to a class variable; which means you can acess it only through the class.
2006-10-18 02:14:08
·
answer #1
·
answered by Anonymous
·
0⤊
2⤋
Only deletomn have some idea about static. Now listne from me.
Normally to access a class member (variable, method), u need an object of that class. However, it's possible to create a member that can be accessed without reference to a specific instance of the class. To create such a member u declare it with the keyword static.
For the rest see page 141 of "the Complete reference java" J2se 5 Edition, By Herbert Schildt. Name of the topic is "Understanding Static". It is explained there beautifully.
OK?
2006-10-19 16:43:39
·
answer #2
·
answered by binaryFusion 5
·
0⤊
0⤋
"static" means that the member (be it an inner class, method, field, whatever) does not require an instance of the class to work. Additionally, all instances share the same static members.
There are various things that result from this for each type of member.
For methods, "this" is not accessible within the static method. That's because the method does not have use of an instance of the class.
For fields, when one instance has it's static field changed, it will affect that static field for all instances. Additionally, you don't need an instance to access the static field.
For inner classes, you don't need an instance of the outer class, to create an instance of the inner class. Additionally, the inner class will not automatically have access to an instance of the outer class.
(Edited to add: Note that "final" makes it so a class, field, method, or variable can't be changed.)
(2nd edit to correct a couple of typos and add the following)
I forgot to mention that there is another use of static. You can use it to define a nameless static method. This nameless method will be executed when the class is loaded, so you can use it to do some complicated initialization. So, the moment the class is used (i.e. a named static method called, an instance is created, a field is referenced, etc...) this nameless method is executed first.
2006-10-18 09:57:50
·
answer #3
·
answered by deletomn 2
·
0⤊
0⤋
In java static means that u dont have to explicitly create an instance in order to use the variables or methods. let me given an example
class A{
static int a;
static myMethod(){
}
}
in order to use the access the method myMethod or variable a u have to create an instance but if we declare them as static then we can use them directly, we dont have to create an instance
so in order to access them we can say
A.a;
A.myMethod()
There is no need to create an instance.
If we declare a variable as static then it will be available for all the instances of that class. if one instance of the class changes it it will be reflected.
2006-10-20 10:18:22
·
answer #4
·
answered by Nagesh K 2
·
1⤊
0⤋
The value of the static variable dont change upto the end of the program.
Visit the website for more details
2006-10-18 09:15:05
·
answer #5
·
answered by Evergreen 2
·
0⤊
1⤋
Tha static keyword when used with a variable uses only one copy of that variable for all the objects of that class, ie, the value remains same for functions or variables using it.
2006-10-18 09:37:38
·
answer #6
·
answered by Dx 2
·
0⤊
1⤋
It means it will retain the value assign to it
2006-10-18 09:13:54
·
answer #7
·
answered by JavaClark 5
·
0⤊
1⤋