June 2017
Beginner
1296 pages
69h 23m
English
static Methods, static Fields and Class MathMost methods execute in response to method calls on specific objects. However, 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. (In Section 10.10, you’ll see that interfaces also may contain static methods.)
Classes often contain convenient static methods to perform common tasks. For example, recall that we used class Math’s static method pow 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 ...
Read now
Unlock full access