QuestionQ7

Working with Methods and Encapsulation

Given:

Question Image

And:

Question Image

What is the resulting output?

Question Image

  • A Option A
  • B Option B
  • C Option C
  • D Option D
Explanation

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.

Community Discussion

No comments yet. Be the first to start the discussion!