I've had some trouble with this for some time now, it should seemlike a stupid problem to most of you.Anyway I just don't completely understand the static keyword. I haveread a few short explanations but none of them suffice. Anexplanation of what it means rather than where I should use it wouldbe greatly appreciated.
It depends upon what are you intended to do. There isno steadfast answer where you should apply themodifier. Whether you are a developer, programmer, orstudent, you embark upon the digital language writercareer field -- be creative.
It means that the field or method is accessible via the class. Example:public class Thing{public static void staticMethod(){ }public void instanceMethod(){ }}The method staticMethod() can be accessed via Thing.staticMethod() andyou don't need an object, whereas with the instanceMethod() you wouldfirst need to create an instance of MyClass to access the method:Thing thing = new Thing();thing.instanceMethod();
If you declare a variable or method static it means that it is a classvariable or method. Then you can access it with something likex = MyClass.staticVariable;but if you don't declare it static you would have to use something likeMyClass obj = new MyClass;x = obj.nonStaticVariable;
http://www.cs.umb.edu/java/keywords/static.html