Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Static keyword

  Asked By: Jesse    Date: Jul 03    Category: Java    Views: 636
  

I've had some trouble with this for some time now, it should seem
like a stupid problem to most of you.

Anyway I just don't completely understand the static keyword. I have
read a few short explanations but none of them suffice. An
explanation of what it means rather than where I should use it would
be greatly appreciated.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Rhys Evans     Answered On: Jul 03

It depends upon what are you intended to do. There is
no steadfast answer where you should apply the
modifier. Whether you are a developer, programmer, or
student, you embark upon the digital language writer
career field -- be creative.

 
Answer #2    Answered By: Mildred Bailey     Answered On: Jul 03

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() and
you don't need an object, whereas with the instanceMethod() you would
first need to create an instance of MyClass to access the method:

Thing thing = new Thing();
thing.instanceMethod();

 
Answer #3    Answered By: Lee Butler     Answered On: Jul 03

If you declare a variable or method static  it means  that it is a class
variable or method. Then you can access it with something like

x = MyClass.staticVariable;

but if you don't declare it static you would have to use something like

MyClass obj = new MyClass;
x = obj.nonStaticVariable;

 
Answer #4    Answered By: Jennifer Davis     Answered On: Jul 03
 
Didn't find what you were looking for? Find more on Static keyword Or get search suggestion and latest updates.




Tagged: