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

Very Important!

Both assignment, and passing a base type value as an argument to a method with a base 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
18
19
20
public static void main (String[] args) {
    Trace.showBuiltInObjects (true);
    Trace.drawStepsOfMethod("f");
    Trace.run ();
    int x = 35;
    int y = x;
    y += 10;
    y = f(y);
    Trace.draw();
}

public static int f(int y) {
    y *= 10;
    return y;
}
001-Value-Hello_f_19

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