what can be static??? classes??? methods??? variables???what happens inside JVM when I have an class whith some static code, and then I create 2 objects with this class. If I try to access a static method which is not synchronized and try to access a non-static method Which is not synchronized using those 2 objects simultaneously. The jvm treats static and non-static methods equally??? The execution of method main, causes a thread. The most important thread. Which is not daemon. Is this true???
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
A method can be static. A variable can be static. Static variables are shared by all users of the class. Static methods are simply methods that can be executed without instantiating the class they are in.
a static variable can't be a reference variable, and a static method can be easily accessed without creating an instance of the class where that method lies. [ December 14, 2002: Message edited by: Melliholic Michael ]
a beginner in java
Leandro Oliveira
Ranch Hand
Joined: Nov 07, 2002
Posts: 298
posted
0
I'm very young with java. I wrote a code and it compiled: import javax.swing.JButton; public class test{ static int a=10; static JButton button=new JButton("button"); }
in this case button is a static variable, which has a reference type! isn't it???
Mellihoney Michael
Ranch Hand
Joined: Nov 27, 2002
Posts: 124
posted
0
leandro oliveira,you are right, I made a mistake! A final var can't be a reference variable!!! Thanks for your reminding!
Neil Laurance
Ranch Hand
Joined: Jul 18, 2002
Posts: 183
posted
0
Originally posted by Melliholic Michael: leandro oliveira,you are right, I made a mistake! A final var can't be a reference variable!!! Thanks for your reminding!
Um, not sure what you are saying here? Both final variables and static final variables are not limited to primitives only. For example:
Returns:
Note how the contents of the final static StringBuffer can change, although the reference itself cannot. :roll: :roll: