This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Ian - This is tricky because you know you don't need an instance to invoke a static method, so what do you do? When you use static methods you have to indicate from which class you're getting the method. In this case try: return Math.sqrt(x); // Math is the class that contains sqrt The rule to remember is: "For static methods, use the dot operator on the class name"
There is another tricky shortcut for similar situations: If you have a static member (variable or method) in one of your classes, (say your class is Dog), and you have an instance of that class (Dog d = new Dog(); ), you can also access static members in the class using the shortcut: d.doStaticMethod(); // using an instance var to access a static method or Dog.doStaticMethod(); The first example is really just a compiler trick, but it works. [ June 04, 2003: Message edited by: Bert Bates ]
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joined: Apr 05, 2001
Thanks, that works fine, need to study up on static methods, do you know any good books?