QuestionQ111

Working with Methods and Encapsulation

Given this class:

Question Image

And this main method, located in a different class:

Question Image

Which three code fragments, when inserted independently, set the value of amount to 100?

Choose three
  • A
  • B
  • C
  • D
  • E
  • F
Explanation

amount is an instance variable. Code in a CheckingAccount constructor can assign it using either an unqualified field reference or this.amount. Because main is static and belongs to another class, it must access the field through the existing CheckingAccount reference, acct.amount; this and an unqualified instance-field reference are not valid there. The variable acct is not in scope inside the constructor.

Learn more

Community Discussion

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