Java Reference
In-Depth Information
myErrorMsgs[0] = new ErrorMsg ();
if (myErrorMsgs[0] == null) {
// This section will not be executed, since myErrorMsgs[0] has been
// assigned to an object.
}
A RRAYS AS P ARAMETERS
Parameters passed to Java methods are passed by value, not by reference. In
COBOL, parameters are passed by reference to a subroutine, although some com-
pilers support an optional “by value” mechanism.
When arrays are passed to methods as parameters, the method cannot change
the array. However, if the array contains objects, then the called method can change
the objects contained in the array. Though not exactly the same as a parameter that
is passed by reference, this can be a useful mechanism to construct a method that
modifies the objects passed to it as an argument.
A way to look at it is that a copy of the reference is made and that copy is
passed into the method. They both point to the same thing, but only the copy can
be changed to point to something different.
M ETHOD M EMBERS
Method members are the functions that a class provides. This concept is similar to
the COBOL subroutine that provided multiple functions based on an ACTION-
SWITCH. Method members are identified by their names (e.g., setErrorMsg ) and
their method signatures (that is, the types and number of parameters). Method
member references are distinguished from data member references by an argu-
ment definition, which is enclosed in an open parenthesis or closed parentheses for
no arguments.
Remember how class data members could be made visible or invisible to other
classes? Class method members can also be qualified with access controls. These
controls define whether other classes can access methods directly. Class method
members can be public, private, or package methods.
Some of Java's method members are not associated with any instance of a class
but rather with all instances of a class. These are called class methods . Since class
methods do not belong to an instance of a class, class methods can access only sta-
tic variables, not instance variables. Such methods are helpful in managing static
variables (for example, resetting a static variable based on some condition).
Search WWH ::




Custom Search