QuestionQ115

Working with Methods and Encapsulation

Given:

Question Image

What is the resulting output?

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

Method parameters named x and y shadow the instance fields. x = x changes only the parameter, while y = this.y assigns the instance field’s default value of 0 to the parameter. Neither field in the second object is changed, so the output is 100 200 : 0 0 :.

Community Discussion

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