Java Reference
In-Depth Information
SR 4.14
A constant might be declared with public visibility, because that would
not violate encapsulation. Because the value of a constant cannot be
changed, it is not generally a problem for another object to access it
directly.
SR 4.15
The modifiers affect the methods and variables in the following ways:
a. A public method is called a service method for an object because
it defines a service that the object provides.
b. A private method is called a support method because it cannot be
invoked from outside the object and is used to support the activi-
ties of other methods in the class.
c. A public variable is a variable that can be directly accessed and
modified by a client. This explicitly violates the principle of encap-
sulation and therefore should be avoided.
d. A private variable is a variable that can be accessed and modified
only from within the class. Variables almost always are declared
with private visibility.
4.4 Anatomy of a Method
SR 4.16
Although a method is defined in a class, it is invoked through a particu-
lar object to indicate which object of that class is being affected. For
example, the Student class may define the operation that computes the
grade point average (GPA) of a student, but the operation is invoked
through a particular Student object to compute the GPA for that stu-
dent. The exception to this rule is the invocation of a static method
(see Chapter 3), which is executed through the class name and does not
affect any particular object.
SR 4.17
An invoked method may return a value, which means it computes a
value and provides that value to the calling method. The calling method
usually uses the invocation and thus its return value, as part of a larger
expression.
SR 4.18
An explicit return statement is used to specify the value that is returned
from a method. The type of the return value must match the return type
specified in the method definition.
SR 4.19
A return statement is required in methods that have a return type other
than void. A method that does not return a value could use a return
statement without an expression, but it is not necessary. Only one
return statement should be used in a method.
SR 4.20
An actual parameter is a value sent to a method when it is invoked.
A formal parameter is the corresponding variable in the header of the
Search WWH ::




Custom Search