Oracle 1Z0-808 Exam question no. 47

Q.– Given:-

class CheckingAccount {
         private int amount;
         public CheckingAccount (int amount) {
                    this.amount = amount; 
         } 
         public int getAmount( ) { 
                    return amount; 
         } 
         public void setAmount (int amount) { 
                    this.amount = amount; 
         } 
         public void changeAmount (int x) { 
                     amount += x;
         }
}

And given this main method, located in another class:-

public static void main(String[] args) { 
CheckingAccount acct = new CheckingAccount ((int) (Math.random( )*1000)); 
//line n1
System.out.println(acct.getAmount( )); 
}

Which three lines, when inserted independently at line n1, cause the program to print a balance? 

A) acct.getAmount() = 0; 

B) this.amount = 0; 

C) acct.setAmount(0); 

D) acct.changeAmount(0); 

E) acct.changeAmount (-acct.amount); 

F) acct.amount = 0; 

G) acct.setAmount(-acct.getAmount( ));


⧪ please give your answer in a comment section.

Post a Comment

3 Comments