Lesson 3.1: Abstraction and Program Design

Unit 3 · Lesson 3.1 · Conceptual

Lesson 3.1: Abstraction and Program Design

🕑 25–30 min· 8 Practice Questions· 4 Mastery Questions· Output Predictor + Bug Hunt

What You'll Learn

  • Define abstraction and explain why it is central to class design
  • Distinguish instance variables from class (static) variables
  • Apply the three-question method to design a class from a specification
  • Explain why instance variables should be private

Key Vocabulary

Term Definition
abstraction Reducing complexity by focusing on the main idea; hiding irrelevant details (EK 3.1.A.1)
data abstraction Separates what data represents from how it is stored; gives data a name without exposing implementation (EK 3.1.A.2)
attribute Data defined in a class outside any method; represents a property of objects (EK 3.1.A.3)
instance variable An attribute whose value is unique to each instance of the class (EK 3.1.A.3)
class variable An attribute shared by ALL instances; declared with the static keyword (EK 3.1.A.3)
behavior An action a class can perform; implemented as a method
UML diagram Unified Modeling Language diagram showing a class's attributes and behaviors

CED EK 3.1.A.1–3.1.A.3

Abstraction reduces complexity by hiding implementation details and exposing only what is necessary. An instance variable's value is unique per object; a class variable (static) is shared by all objects.

What Is Abstraction?

A BankAccount class abstracts a real account. You include balance and methods like deposit(). You ignore the bank's server architecture and network protocols.

Identifying Attributes and Behaviors

Scenario: model a Student in a grade-book program.

Category Examples
Attributes (data) name (String), grade (int), gpa (double)
Behaviors (methods) getGpa(), setGrade(int g), toString()
Irrelevant details home address, locker number, lunch preference

Instance Variables vs Class Variables

Instance vs Class Variable

public class Student {
    private String name;           // instance variable -- unique per object
    private int grade;
    private static int total = 0;  // class variable -- shared by ALL objects

    public Student(String n, int g) {
        name = n; grade = g;
        total++;  // increments the ONE shared copy
    }
}

After creating two Students, each has its own name, but total is 2 for both.

Designing a Class: Three Questions

Question Guides You To
What is it? The class name (a noun)
What does it have? Instance variables (attributes)
What can it do? Methods (behaviors)

AP Trap: Attributes vs Behaviors

Attributes are nouns (data stored in the object). Behaviors are verbs (actions the object performs). getBalance() is a behavior, NOT an attribute.

AP Trap: Static vs Instance

Every object needs its OWN copy → instance variable. All objects share ONE copy → class variable (static). A counter of objects created is almost always static.

AP Trap: Private Instance Variables

Instance variables should be private unless the specification says otherwise. Public instance variables break encapsulation and appear as distractors on the AP exam.

Real-World Connection: A GPS app models roads as objects with attributes (speedLimit, laneCount) and behaviors (getCongestion()).

Summary

  • Abstraction hides irrelevant details and focuses on essential properties.
  • An instance variable belongs to a specific object; a class variable (static) is shared by all objects.
  • Design a class by identifying its name, attributes, and behaviors.
  • Instance variables representing attributes should be declared private.
Tier 2 · AP Practice

Practice Questions

MCQ 1
Which BEST describes abstraction in OOP?
A Ensuring all instance variables are public
B Reducing complexity by focusing on essential properties and hiding irrelevant details
C Requiring every class to extend another class
D Forcing all methods to return void
B is correct. EK 3.1.A.1.
MCQ 2
For a TrafficLight class, which is BEST classified as an attribute (instance variable)?
A changeToRed()
B currentColor
C getCycleTime()
D flashWarning()
B is correct. currentColor stores state. A, C, D are actions (behaviors).
MCQ 3
private static int totalCreated; is inside Counter. Which is TRUE?
A Each Counter object has its own copy of totalCreated
B totalCreated cannot be accessed by any Counter method
C All Counter objects share a single copy of totalCreated
D totalCreated resets to zero when a new Counter is created
C is correct. static = one shared copy for all instances.
MCQ 4
Which class design BEST applies abstraction for a Book class?
⚠ Predict the answer before reading the options.
A Attributes: title, author, isbn; Behaviors: getTitle(), isCheckedOut()
B Attributes: title, author, isbn; Behaviors: none
C Attributes: none; Behaviors: getTitle(), getAuthor()
D Attributes: printerModel, networkSpeed; Behaviors: scanPage()
A is correct. A well-designed class has relevant attributes AND behaviors.
MCQ 5
The following class violates standard OOP practice. Why?
public class Thermometer {
    public double temperature;
    public double humidity;
}
A Constructors should be private, not public
B The class is missing a static counter variable
C Instance variables should be private to enforce encapsulation
D A class with two instance variables cannot be properly abstracted
C is correct. Public instance variables allow direct external modification, breaking encapsulation.
MCQ 6
Which is the MOST appropriate use of a static variable?
A Storing the name of each individual Employee
B Counting the total number of Employee objects created
C Storing the salary of each Employee
D Tracking the department of each individual Employee
B is correct. A total count is shared by all objects -- perfect for static. A, C, D vary per individual object.
MCQ 7
Which statements about a Vehicle class are TRUE?
I. make and model are appropriate instance variables.
II. accelerate() and brake() are appropriate behaviors.
III. roadSurfaceComposition is an appropriate Vehicle instance variable.
A I only
B I and II only
C II and III only
D I, II, and III
B is correct. I and II are valid. III is false: road surface belongs to a Road class, not Vehicle.
MCQ 8
After Dog d1 = new Dog("Rex",3); and Dog d2 = new Dog("Spot",5);, where dogCount is static and incremented per constructor call, which describes the state?
A d1.name="Rex", dogCount=1
B d1.name=d2.name="Rex", dogCount=2
C d1.name="Rex", d2.name="Spot", dogCount=2
D d1.name="Rex", d2.name="Spot", dogCount=1
C is correct. Each object has its own name. dogCount is static, incremented twice = 2.
PRACTICE WITH A GAME — CHOOSE ONE:
Output Predictor: Static vs Instance
Predict the printed output.
Question 1 of 3  ·  Score: 0

Done!
You got 0 of 3 correct.
Bug Hunt: Class Design
Click the line with the bug, or 'No bug'.
Question 1 of 3  ·  Score: 0
No bug — code is correct
Done!
You got 0 of 3 correct.
Tier 3 · AP Mastery

Mastery: Abstraction and Program Design

MCQ 1
Which bank account design demonstrates the BEST abstraction?
A Attributes: networkLatency, serverPort; Behaviors: getBalance()
B Attributes: balance, accountNumber; Behaviors: none
C Attributes: none; Behaviors: deposit(double), withdraw(double)
D Attributes: balance, accountNumber; Behaviors: deposit(double), withdraw(double)
D is correct. Complete abstraction needs both relevant attributes and behaviors.
MCQ 2
The following class is NOT correctly designed. Which change would BEST fix it?
public class Inventory {
    public String itemName;
    public int quantity;
}
A Change static int to a non-static instance variable
B Change public itemName and public quantity to private
C Remove all static variables from the class
D Change the class to private class Inventory
B is correct. itemName and quantity should be private (EK 3.3.A.5).
MCQ 3
After lib1.addCheckout(); lib1.addCheckout(); lib2.addCheckout(); where addCheckout() increments the static variable totalCheckouts, what is the value of totalCheckouts?
A 1
B 3
C 2
D 0
B is correct. totalCheckouts is static (shared). Each call increments it. 3 calls = 3.
MCQ 4
Which CORRECTLY distinguishes instance variable from class variable?
A Instance: shared by all; Class: unique per object
B Instance: declared with static; Class: no static keyword
C Instance: unique per object, no static keyword; Class: shared by all, declared with static
D Instance: only primitive types; Class: only reference types
C is correct. EK 3.1.A.3. A and B reverse the definitions. D is false.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]