Given:
And the following code fragment:
What is the output?
stVar is a class-level static field shared across all instances, whereas var belongs to each individual object. The first output uses the unchanged static value 100 and t1’s updated instance value 300. The later assignment changes the shared static value to 300, while the new t2 object retains its default instance value 200.
stVar
var
100
t1
300
t2
200
Community Discussion