PrepGo

AP Computer Science A Flashcards: Anatomy of a Class

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What is data encapsulation?
Data encapsulation is a technique in which the implementation details of a class are kept hidden from external classes.
Card 1 of 10

All Flashcards (10)

What is data encapsulation?
Data encapsulation is a technique in which the implementation details of a class are kept hidden from external classes.
What is the main goal of designating access and visibility constraints in a class?
The main goal is to control which parts of a class are exposed to the outside world, forming a stable interface while hiding the internal implementation details.
What is the relationship between access modifiers and visibility constraints?
Access modifiers like `public` and `private` are the keywords used in code to designate and enforce visibility constraints on classes, data, and methods.
If a method in a `BankAccount` class needs to be called by an external `ATM` class, what access modifier should the method have?
The method should be designated as `public` to allow access from classes outside the `BankAccount` class.
To properly implement encapsulation, what access modifier should be used for a class's instance variables?
To implement encapsulation, it is good programming practice to designate the instance variables as `private`.
How does using the `private` keyword for instance variables support data encapsulation?
By making instance variables `private`, their implementation details are hidden and access is restricted to the declaring class, which is the core principle of encapsulation.
A programmer wants to create a `Person` class with an `age` attribute. To prevent other classes from directly changing the age, what keyword should be used when declaring the `age` variable?
The programmer should use the `private` keyword to restrict access to the `age` variable to within the `Person` class itself.
Why should access to a class's attributes be kept internal?
Access to attributes should be kept internal to the class in order to accomplish data encapsulation.
What is the function of the `public` keyword?
The `public` keyword is an access modifier that allows access to a class member from classes outside the declaring class.
What is the function of the `private` keyword?
The `private` keyword is an access modifier that restricts access to a class member (data or method) to only the declaring class.