Java Reference
In-Depth Information
{
//Line 4
int number = 6;
//Line 5
System.out.println("Line 6: Before calling"
+ "the method "
+ "primFormalParam, "
+ "number = " + number);
//Line 6
primFormalParam(number);
//Line 7
System.out.println("Line 8: After calling "
+ "the method "
+ "primFormalParam, "
+ "number = " + number);
//Line 8
} //end main
//Line 9
public static void primFormalParam( int num)
//Line 10
{
//Line 11
System.out.println("Line 12: In the method "
+ "primFormalParam, "
+ "before changing, num = "
+ num);
//Line 12
num = 15;
//Line 13
System.out.println("Line 14: In the method "
+ "primFormalParam, "
+ "after changing, num = "
+ num);
//Line 14
} //end primFormalParam
//Line 15
}
//Line 16
Sample Run:
Line 6: Before calling the method primFormalParam, number = 6
Line 12: In the method primFormalParam, before changing, num = 6
Line 14: In the method primFormalParam, after changing, num = 15
Line 8: After calling the method primFormalParam, number = 6
The preceding program works as follows. The execution begins at the method main . The
statement in Line 5 declares and initializes the int variable number (see Figure 7-3).
main
number
6
FIGURE 7-3 The method main and its variable number
The statement in Line 6 outputs the value of number before calling the method
primFormalParam . The statement in Line 7 calls the method primFormalParam . The
Search WWH ::




Custom Search