Here is a short program for your review:
// 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 a partial 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.
- Think about what happens next. It is easy to make a mistake here.
- The number currently held in value is printed out.
|