-1

Possible Duplicate:
static in the main class java and non static in constructor

i just want to know if people can agree with me on the knowledge I have about static variable and methods as I'm still learning java in its early concepts.

static variables means when both objects or instances of the class gets shared the same variables. static methods simply means methods that refer to the class that it is written in.

Anyone can correct me if I'm wrong or can add any more information are welcome as I want to be able to learn java to its fullest and do amazing things with java in the future! :)

Happy coding!

2
  • 3
    I advise you to refer to the Java tutorial Commented Oct 19, 2011 at 1:46
  • Here's a good read if you're trying to learn more about it. Your example isn't entirely correct. What do you mean by static in Java? Commented Oct 19, 2011 at 1:46

2 Answers 2

2

You might want to read - Class Variables (Static Fields) and Class Methods.

Sign up to request clarification or add additional context in comments.

Comments

2

Static variables are shared for all instances of the class.

Static methods are accessed directly by class name, not belong to any instances.

1 Comment

Correct for static variables. For static methods, not really. It is true that you access static methods by prefixing them with the name of their enclosing type, as in ClassName.Method(), but the reason you might want to do that is because an instance of the class is not required to execute the method.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.