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

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

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “Which three pieces of code, when inserted independently, set the value of amount to 100?

  1. 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

  2. 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

  3. Given the following class:

    public class CheckingAccount {
    public int amount:
    //line n1
    }

    Answer: CDE

Leave a Reply

Your email address will not be published. Required fields are marked *