AP Computer Science a Flashcards: Class Variables And Methods

Study Class Variables And Methods 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

State whether class methods can be abstract.

Tap card or press Space to flip

ANSWER

No. Abstract requires inheritance; static methods cannot be overridden.

1 / 38

AP Computer Science a: Class Creation

All flashcards

38 cards

What this deck covers

This deck focuses on Class Variables And Methods, 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 19Practice questions for this set
How does the static method interact with the class variable in this code?
// BankAccount demonstrates class variables (static) and class methods (static).
public class BankAccount {
    // Class variable shared by all accounts in the bank.
    private static double bankTotalBalance = 0.0;

    // Instance variable unique to each BankAccount object.
    private double accountBalance;

    // Constructor initializes an account with an opening deposit.
    public BankAccount(double openingDeposit) {
        accountBalance = openingDeposit;
        // Update the class-level total whenever an account is created.
        bankTotalBalance += openingDeposit;
    }

    // Static (class) method returns the total balance across all accounts.
    public static double getBankTotalBalance() {
        return bankTotalBalance;
    }

    // Instance method deposits money into this account and updates the class total.
    public void deposit(double amount) {
        accountBalance += amount;
        bankTotalBalance += amount;
    }

    // Instance method withdraws money from this account and updates the class total.
    public void withdraw(double amount) {
        accountBalance -= amount;
        bankTotalBalance -= amount;
    }

    // Main method demonstrates creating accounts and adjusting balances.
    public static void main(String[] args) {
        BankAccount a = new BankAccount(100.0);
        BankAccount b = new BankAccount(50.0);
        a.deposit(25.0);
        b.withdraw(10.0);
        System.out.println(BankAccount.getBankTotalBalance());
    }
}
Choose an answer

Keep your progress across every deck

Free account · cards you mark are saved to it