Remember that Java is case-senstive, so static and void. Be sure not to capitalize them either in code, or when referring to them in text.
static and void are distinct concepts. You use static when you want a member to be static (and everything that entails). void is used to indicate that a method returns no value. If the method returns a value, it will indicate the type of that value; such as int or String.
So, for a static method, it's not a choice between static void and static, but between static void and static int, or static String, or whatever other type a method might return.
Static is used when you want to reference a method or variable without instantiating an object. An example would be the "main" method which is always declared static. Another example is with the Math object, which has PI declared as static so you can reference it without instantiating an object of Math.
void is the return type of a method that doesn't return anything.
If you have a method that returns an int for example you would declare it
but if your method doesn't return anything
Whoever loves discipline loves knowledge, but whoever hates correction is stupid. (Proverbs 12:1 NIV)
I just want to illustrate what Bear and Brian have said using the following example.
You can realize that we didn't need to create a ClassOne object on which to call the methods aNumber() and voidMethod(). However, we needed to create the object classone and use it to call the method anotherNumber();
I am always surprised at the added knowledge i can get from others when i give my opinion on a topic.
Forget about void method for the time being. There are a few things about static methods.
1: Most important: the rule is that all class members are instance members.
So static members are exceptions to that rule because things static do not belong to an object. They belong to the class. So things static should be unusual. And you only make things static with good reason.
Find the most dubious classification of methods known to modern science; if a method's type ends 68 (usually 1368) it is a candidate for being made static.
Never make a method static if you want to override it or if it comes from an interface. Interface methods are never static (well, not until Java8).
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop