CSC300: Assignment and Parameters with Primitive Types [14/24] Previous pageContentsNext page

Very Important!

Both assignment, and passing a primitive type value as an argument to a method with a primitive type argument, results in copying the data to a new place in memory.

Modifying the data in the new place in memory does not affect the memory where the data was copied from!

06
07
08
09
10
11
12
13
14
15
16
17
public static void main (String[] args) {
    // Try tracing the execution of method f
    int x = 35;
    int y = x;
    y += 10;
    y = f(y);
}

public static int f(int y) {
    y *= 10;
    return y;
}

Note: The assignment at line 13 has not been done yet!

The variable y in the main program still contains the value it had before f was called.

Previous pageContentsNext page