AP Computer Science a Flashcards: Methods Passing And Returning References

Study Methods Passing And Returning References in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

QUESTION

Which keyword is necessary to return an object from a method?

Tap card or press Space to flip

ANSWER

return. Required for all method returns.

1 / 36

AP Computer Science a: Class Creation

All flashcards

36 cards

What this deck covers

This deck focuses on Methods Passing And Returning References, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

Practice questions

1 of 15Practice questions for this set
Based on the code snippet above, what is returned by the method deposit? Describe its significance.
public class BankAccount {
    private String accountNumber;
    private double balance;

    public BankAccount(String accountNumber, double balance) {
        this.accountNumber = accountNumber;
        this.balance = balance;
    }

    // Adds funds to this account
    public void deposit(double amount) {
        balance += amount;
    }

    // Deposits then returns this same account reference
    public BankAccount depositAndReturn(double amount) {
        deposit(amount);
        return this;
    }

    public double getBalance() {
        return balance;
    }

    public static void main(String[] args) {
        BankAccount acct = new BankAccount("A100", 50.0);
        BankAccount ref = acct.depositAndReturn(25.0);
        System.out.println(acct.getBalance());
        System.out.println(ref.getBalance());
    }
}
Choose an answer

Keep your progress across every deck

Free account · cards you mark are saved to it