Java Reference
In-Depth Information
jects of the class, such as returning the next available serial number or
something of that nature.
A static method can access only static fields and other static methods
of the class. This is because non- static members must be accessed
through an object reference, and no object reference is available within
a static methodthere is no this reference.
In this topic when we use the term method, we usually mean the non-
static kind. When the context makes it ambiguous, we use the term non-
static method to be clear.
Exercise 2.9 : Add a static method to Vehicle that returns the highest
identification number used thus far.
2.6.2. Method Invocations
Methods are invoked as operations on objects via references using the
dot ( .) operator:
reference.method ( arguments )
In the BodyPrint example we invoke the println method on the object
referred to by the static reference System.out and passing a single String
argument formed by concatenating a number of other strings.
Each method is declared to have a specific number of parameters, each
of a specific type. The last parameter of a method can be declared as a
sequence of parameters of a given type. This is indicated by an ellipse
( ... ) after the type name. For example, String... is a sequence of zero
or more String objects. Sequence parameters allow you to invoke the
method by passing in a variable number of arguments, some of which
will correspond to that sequence. These variable argument methods are
described in the next section.
 
Search WWH ::




Custom Search