This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
First he compiler made me put the printResults outside of main. I don't understand this??? Why can't I have a method inside of main? Next the compiler will not let me call printResults from inside of main. When I call the printResult method (as shown above), I get an error saying you cannot call a non-static method from a static context???
Thank you, Mitch
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ December 05, 2004: Message edited by: Dirk Schreckmann ]
Bruce Eckel ("Thinking in Java, 3rd Ed") explains it as follows:
"[A static method is] the equivalent of a global function (from C)... It means that there is no 'this' (no per-instance data) for that particular method.
"You cannot call non-static methods from inside static methods (although the reverse is possible", and you can call a static method for the class itself, without any object. In fact, that's primarily what a static method is for."
Please take a look at the JavaDoc for "java.lang.Math". You'll notice that most of the math functions (abs(), sin(), cos(), etc etc) are all static functions. The reason is simple - you shouldn't have to create an entire object just to get the absolute value of a number. You just call ... a "static method": "abs (x)".