| preferred AP College board partner for AP classes
Login
 
Register
AP Computer Science A/Unit 2: Using Objects
Start Practice Test
Share
Java Constructor Overloading
< Prev
Next >

Identify, using its signature, the correct constructor being called.
Consider the following class definition:

public class BankAccount {
    private String owner;
    private double balance;
    
    public BankAccount(String name) {
        owner = name;
        balance = 0.0;
    }
    
    public BankAccount(String name, double amount) {
        owner = name;
        balance = amount;
    }
    
    public double getBalance() {
        return balance;
    }
}

Which of the following constructor calls will result in a BankAccount object with a balance of 0.0?

A

BankAccount account = new BankAccount(“John”, 50.0);

B

BankAccount account = new BankAccount(“John”);

C

BankAccount account = new BankAccount();

D

BankAccount account = new BankAccount(“John”, 100.0);

Check Answer
APFIVE © 2020.
Email: [email protected]|Privacy Policy