Here is the program:
// Review Program
//
class Alteration
{
void zero ( int x )
{
x = 0;
}
}
class AlterTest
{
public static void main ( String[] args )
{
Alteration alt = new Alteration();
int value = 27;
System.out.println( "Before:" + value );
alt.zero( value );
System.out.println( "After:" + value );
}
}
|
Here is the full description of the action:
- The program starts running with the static main method.
- An Alteration object is constructed.
- The default constructor is used, since the class Alteration
did not define a constructor.
- The Alteration object contains the zero() method.
- The primitive int variable value is initialized to 27.
- The number currently held in value is printed out.
- The zero() method is called with value as a parameter.
- The number held in value (27) is copied to
the formal parameter x.
- The zero() method changes x to zero.
- Control returns to the caller; value has not been altered.
- The number currently held in value is printed out.
|