Class Methods
class method
is typically a method that does not operate on an instance of the class, but
that logically makes sense as part of the class (remember there are no
stand-alone functions in Java).
For instance, the valueOf method in the String class returns
the string equivalent of its argument.
Like accessing class variables, class methods should be called
using the class
name rather than an object name:
String.valueOf(7 + 5)
A class method uses the keyword
static
in its signature. (What is a class method that we all know and love?!)
Note: A class method can only call another class method directly
(i.e. not using dot-notation).
Look back at the example code for
Type Conversions. What do you notice about the
2 method calls?