Given the following class:
And given the following main method, located in another class:
Which three pieces of code, when inserted independently, set the value of amount to 100?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
C, D, E – correct
A – not correct ( main method is in diff class and amount var is not declared)
B – not correct (cant use this key word for amount since amount property of CheckingAccount class)
C – Correct (acct is object of CheckingAccount class which has amount property which is public)
D – Correct It calls the constructor and set the value 100
E – Correct this.amount is valid in constructor
F – not correct – cant use acct in constructor
TF??
public class CheckingAccountQ32 {
public int amount;
public CheckingAccountQ32(){
amount=100;
this.amount=100;
}
public static void main(String[] args) {
CheckingAccountQ32 acc = new CheckingAccountQ32();
acc.amount=100;
}
}
CDE
Given the following class:
public class CheckingAccount {
public int amount:
//line n1
}
Answer: CDE
C, D, E are the correct answers