Java Reference
In-Depth Information
18
.
When a program executes, the execution always begins with the first
statement in the method
main
.
19
.
User-defined methods execute only when they are called.
20
.
A call to a method transfers control from the caller to the called method.
21
.
In a method call statement, you specify only the actual parameters, not their
data type or the method type.
22
.
When a method exits, control goes back to the caller.
23
.
A method that does not have a return data type is called a
void
method.
24
.
A return statement without any value can be used in a
void
method.
25
.
If a return statement is used in a
void
method, it is typically used to exit the
method early.
26
.
In Java,
void
is a reserved word.
27
.
A
void
method may or may not have parameters.
28
.
To call a
void
method, you use the method name together with the actual
parameters in a stand-alone statement.
29
.
A formal parameter receives a copy of its corresponding actual parameter.
30
.
If a formal parameter is of the primitive data type, it directly stores the value
of the actual parameter.
31
.
If a formal parameter is a reference variable, it copies the value of its
correspondingactualparameter,whichistheaddressoftheobject
where the actual data is stored. Therefore, if a formal parameter is a
reference variable, both the formal and actual parameters refer to the
same object.
32
.
The scope of an identifier refers to those parts of the program where it is
accessible.
33
.
Java does not allow the nesting of methods. That is, you cannot include the
definition of one method in the body of another method.
34
.
Within a method or a block, an identifier must be declared before it can be
used. Note that a block is a set of statements enclosed within braces. A
method's definition can contain several blocks. The body of a loop or an
if
statement also forms a block.
35
.
Within a class, outside every method definition (and every block), an
identifier can be declared anywhere.
36
.
Within a method, an identifier used to name a variable in the outer block of
the method cannot be used to name any other variable in an inner block of
the method.
37
.
The scope rules of an identifier declared within a class and accessed within a
method (block) of the class are as follows:
Search WWH ::
Custom Search