AP Computer Science A 50 Flashcards Intermediate 100% Free

AP Computer Science A:: Writing Classes

Created by Chat Robotics Community  ·  Updated 2026-08-31

Curriculum Overview

Comprehensive, high-yield AP Computer Science A study deck focusing on Writing Classes. Features 50 rigorous, curriculum-aligned flashcards designed for intermediate-level mastery. Core concepts covered include Writing Classes, key problem-solving heuristics, foundational formulas, and exam-tested application scenarios. Ideal for active recall review, spaced repetition study, and scoring in the top percentile.

Topics & Key Concepts

Java Only READ This Given String Mutator Science Accessor Computer

Sample Flashcard Questions & Answers

Showing 8 of 50 cards
Question #1 Active Recall

What are the two main components typically found inside a well-designed Java class?

- **A)** Only constructors, with no other methods allowed
- **B)** Only a single \(main\) method
- **C)** A class can contain only one instance variable and no methods
- **D)** INSTANCE VARIABLES (data/state the object holds) and METHODS (behaviors the object can perform)

Answer & Explanation:
**Answer: D)**

A class's instance variables define its state, while its methods define how that state can be accessed, changed, or acted upon.
Question #2 Active Recall

What is ENCAPSULATION, as it applies to writing Java classes?

- **A)** Making every instance variable and method \(public\) so anything can access them directly
- **B)** A technique used only for primitive data types, never for objects
- **C)** A synonym for inheritance
- **D)** Bundling an object's data (instance variables) together with the methods that operate on it, while restricting DIRECT outside access to that data (typically by making instance variables \(private\))

Answer & Explanation:
**Answer: D)**

Encapsulation is a core object-oriented principle: protecting an object's internal state from uncontrolled outside modification by requiring interaction through defined methods.
Question #3 Active Recall

Why are instance variables conventionally declared \(private\) in a well-designed class?

- **A)** To prevent outside code from directly accessing or modifying them, forcing all interaction to go through the class's own methods, which can validate or control how the data changes
- **B)** \(private\) instance variables cannot be given values at all
- **C)** Java requires all instance variables to be \(private\) or the code will not compile
- **D)** Declaring variables \(private\) makes the program run faster

Answer & Explanation:
**Answer: A)**

Restricting direct access lets the class control and validate how its own data is changed -- the core motivation behind encapsulation.
Question #4 Active Recall

What is the purpose of an ACCESSOR method (also called a 'getter'), such as \(public\ int\ getAge()\ \{\ return\ age;\ \}\)?

- **A)** Accessor methods must always return \(void\)
- **B)** To allow outside code to READ the value of a \(private\) instance variable, without allowing direct modification of it
- **C)** To delete an instance variable
- **D)** To allow outside code to directly CHANGE a \(private\) instance variable's value

Answer & Explanation:
**Answer: B)**

Accessor ('getter') methods provide controlled READ-ONLY access to otherwise-private data.
Question #5 Active Recall

What is the purpose of a MUTATOR method (also called a 'setter'), such as \(public\ void\ setAge(int\ newAge)\ \{\ age\ =\ newAge;\ \}\)?

- **A)** To permanently prevent a variable from ever being changed
- **B)** To allow outside code to READ a variable's value without changing it
- **C)** To allow outside code to CHANGE the value of a \(private\) instance variable in a controlled way, often including validation logic
- **D)** Mutator methods must always return the new value as an \(int\)

Answer & Explanation:
**Answer: C)**

Mutator ('setter') methods provide controlled WRITE access, and importantly, can include validation logic that a direct \(public\) variable could never enforce.
Question #6 Active Recall

Why might a MUTATOR method be considered better design than making an instance variable directly \(public\), even though both ultimately allow the value to be changed?

- **A)** A mutator method can include VALIDATION logic (e.g., rejecting a negative age) before actually changing the variable, whereas a \(public\) variable can be set to ANY value with no restriction or checking whatsoever
- **B)** Mutator methods and public variables provide identical levels of control with no meaningful difference
- **C)** Mutator methods can never actually change a variable's value
- **D)** Public variables always include automatic validation, while mutator methods never do

Answer & Explanation:
**Answer: A)**

This validation capability is the single biggest practical advantage of encapsulation via mutator methods over exposing raw \(public\) instance variables.
Question #7 Active Recall

What is the purpose of a CONSTRUCTOR in a class definition?

- **A)** A synonym for an accessor method
- **B)** A special method (same name as the class, no return type) that runs automatically when \(new\) creates an object, used to initialize that object's instance variables to appropriate starting values
- **C)** A method used to permanently destroy an object
- **D)** A method that must be called manually every time an object's data needs to change

Answer & Explanation:
**Answer: B)**

Constructors set up a newly created object's initial state, running exactly once at the moment of object creation via \(new\).
Question #8 Active Recall

Can a single Java class have MULTIPLE constructors?

- **A)** Yes, through CONSTRUCTOR OVERLOADING -- multiple constructors with the SAME name (the class name) but DIFFERENT parameter lists, allowing objects to be created in different ways
- **B)** No, Java allows exactly one constructor per class, no exceptions
- **C)** Yes, but only if all constructors have identical parameter lists
- **D)** A class can have multiple constructors only if none of them accept any parameters

Answer & Explanation:
**Answer: A)**

Constructor overloading lets a class support several different ways to initialize a new object, distinguished by their parameter lists (number, order, or types of parameters).

Want to study all 50 flashcards with spaced repetition?

Practice with Anki-style scheduling, Hands-Free audio commute mode, and AI Tutor explanations.

Start Studying Full Deck Now

How You Can Study This Deck on Chat Robotics

Anki Spaced Repetition (SRS)

Algorithms schedule review intervals automatically so you retain 90%+ in minimum study time.

Hands-Free Audio Commute Mode

High-fidelity Neural Text-To-Speech reads questions and answers aloud with customizable delay timers.

Built-in AI Tutor Assistant

Stuck on a tricky concept? Click "Ask AI" on any card to receive instant deep-dive step-by-step explanations.

Subdeck & Tag Organization

Organize and filter by topic tags or drill entire subdeck hierarchies sequentially in Subdeck Scheduler.