Java Reference
In-Depth Information
x++;
}
static void G()
{
−− x;
}
public static void main ( String [ ]
args )
F() ; // x=1
G() ; // x=0
F() ; // x=1
System . out . println ( "value of x:" +x ) ;
}
}
The program displays in the console: value of x:1 . The various program
execution steps are visualized as shown in Figure 3.2. Note that in this diagram
we split the memory into two parts: The local function call stack memory
(function variables) and the global memory (static variables and referenced
structures). Thus in Java, we can voluntarily alter the calling environment
by handling arrays and other non-primitive user-defined typed objects that are
manipulated by their references . We will explain in further detail these function
side-effects in the following two chapters dealing with arrays and objects.
3.4.4 Function signatures and function overloading
Java is a typed programming language, and functions/procedures declared in
Java are also typed by their signature. The signature of the following declared
function:
static TypeR F(Type1 arg1, Type2 arg2, ..., TypeN argN)
{
TypeR result;
block_instructions;
return result;
}
is the Cartesian product of the type of its arguments:
Type1
×
Type1
×
TypeN .
In other words, the signatures of functions are their ordered sequence of
parameter types. Thus provided that functions have different signatures, they
can actually bear potentially the same name; That is, a given function can be
 
Search WWH ::




Custom Search