Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Methods
-
Methods are part of an object. Identify the owning object as an implicit
parameter, which is preceeded by the method name, separated by a period.
-
The parameters you want to pass in are called explicit parameters,
which are preceeded by type.
-
A method may have 0 - to - many explicit parameters.
-
The implicit parameters, explicit parameters, and method name make up the
methods signature. You can have multiple methods with the
same name, as long as the explicit parameters differ.
-
Note that, in Java, a different return type does not change the signature.
As a matter of fact, two methods with identical signatures and different
return types will cause a compiler error.
-
Methods also have keywords for access control and ownership.
-
public, private, protected: define the scope of the method.
-
static: define whether an object must be instantiated or not
-
A return value specifies the type of data that is returned. This
can be any object, any primitive, or void if nothing is returned.
A method can only return one value, though you can return multiple values
by enclosing them in an object.
See Previous Example
Accessor Methods


Created by: Brandan
Jones January 4, 2002