February 2014
Beginner
1248 pages
62h 25m
English
Although most methods execute in response to method calls on specific objects, this is not always the case. Sometimes a method performs a task that does not depend on an object. Such a method applies to the class in which it’s declared as a whole and is known as a static method or a class method.
It’s common for classes to contain convenient static methods to perform common tasks. For example, recall that we used static method pow of class Math to raise a value to a power in Fig. 5.6. To declare a method as static, place the keyword static before the return type in the method’s declaration. For any class imported into your program, you can call the class’s static methods by specifying the name ...
Read now
Unlock full access