QuestionQ176

Working with Methods and Encapsulation

Given:

Question Image

And the following code fragment:

Question Image

What is the output?

  • A 300:300 200:300
  • B 300:100 200:300
  • C 300:0 0:300
  • D 100:300 300:200
Explanation

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.

Community Discussion

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