public class PrimitiveType { { int number = 6; + "the method funcPrimFormalParam number = " + number); funcPrimFormalParam(number); + "the method funcPrimFormalParam number = " + number); } public static void funcPrimFormalParam(int num) { + "changing, num = " + num); num = 15; } }
Before calling the method funcPrimFormalParam, number = 6 In the method funcPrimFormalParam, before changing, num = 6 In the method funcPrimFormalParam, after changing, num = 15 After calling the method funcPrimFormalParam, number = 6
main
.
The segment int number = 6;
declares and initializes the int variable number.
The statement
+ "the method funcPrimFormalParam number = " + number);
funcPrimFormalParam
.
The statement funcPrimFormalParam(number);
calls the method funcPrimFormalParam
. The value of the variable number is passed to the formal parameter num.
The statement
+ "changing, num = " + num);
num = 15;
changes the value of num to 15.
The statement System.out.println("the mehod funcPrimFormalParam, after changing, num = " + num);
outputs the value of num. After this statement executes, the method funcPrimFormalParam
exits and control goes back to the method main.
The statement
+ "the method funcPrimFormalParam number = " + number);
funcPrimFormalParam
.