CSC301: Storage: Variables and fields [2/8] |
Storage
Sharing
Initialization
file:XFields.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package algs12; import stdlib.*; public class XFields { public static int classVariable = 42; public int objectVariable = classVariable++; public void f(int localVariable1) { int localVariable2 = StdRandom.uniform (100); if (localVariable1 > 0) f (localVariable1 - 1); } public static void main (String[] args) { Trace.drawSteps (); Trace.run (); XFields a = new XFields (); XFields b = new XFields (); a.f(1); b.f(1); } }
Here is the state just before the main function ends:
(This example revealed a bug in my trace software. You can download a corrected copy here: file:Trace.java)