QuestionQ104

Working with Methods and Encapsulation

Given the following code:

Question Image

What is the output?

  • A Compilation fails.
  • B false true
  • C true false
  • D true true
  • E false false
Explanation

isAvailable initially has the value true, so the first print outputs true. doStuff() returns !isAvailable, which is false at that moment. That result is assigned to the static field and printed, producing true false.

Community Discussion

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