Given this class:
And this main method, located in a different class:
main
Which three code fragments, when inserted independently, set the value of amount to 100?
amount
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.
CheckingAccount
this.amount
acct.amount
this
acct
Community Discussion