Given:
And:
What is the resulting output?
A static field is shared by every instance, while each instance has its own ns field. The second constructor call does not satisfy s < ns, so that object's ns remains its default value of 0. The third constructor call updates the shared s to 125; therefore all three print calls show s = 125, while the instance values are 100, 0, and 125, respectively.
ns
s < ns
0
s
125
s = 125
100
Community Discussion