APCSP Abstraction Concepts 3 — Questions and Answers
Question 1: Which of the following is NOT a benefit of using abstractions in programming?
- Reducing code complexity
- Making programs easier to maintain
- Eliminating all possible bugs automatically (Correct answer)
- Allowing code reuse across different programs
Correct answer: Eliminating all possible bugs automatically
Abstraction helps manage complexity and reuse code, but it does not automatically eliminate bugs.
Question 2: The Internet Protocol (IP) is an abstraction that lets applications send data without worrying about the physical network. Which layer of the internet abstraction stack does IP belong to?
- Application layer
- Transport layer
- Internet layer (Correct answer)
- Physical layer
Correct answer: Internet layer
IP operates at the internet (network) layer, abstracting physical routing from applications.
Question 3: A programmer writes a `Car` object with properties `speed` and `fuel` and a method `accelerate()`. Users of the object call `accelerate()` without knowing the engine physics. This is an example of:
- Sequencing
- Iteration
- Object abstraction / encapsulation (Correct answer)
- Boolean logic
Correct answer: Object abstraction / encapsulation
Encapsulating data and behavior inside an object and exposing only a method is a form of abstraction.
Question 4: What does it mean for an abstraction to 'leak'?
- The abstraction uses too much memory
- Details that should be hidden become visible and must be handled by the user (Correct answer)
- The program crashes at runtime
- The source code is accessible to end users
Correct answer: Details that should be hidden become visible and must be handled by the user
A leaky abstraction is one where hidden implementation details surface and the caller must deal with them.
Question 5: In AP CSP, which of the following best represents a 'high-level' abstraction compared to a 'low-level' one?
- Machine code vs. transistor switching
- Python code vs. machine code (Correct answer)
- Binary digits vs. electrical voltages
- Assembly language vs. Python code
Correct answer: Python code vs. machine code
Python is a high-level abstraction that hides the machine code a computer actually executes.
Question 6: When a programmer uses a variable name like `totalScore` instead of a memory address, they are using:
- A hardware interrupt
- A naming abstraction that hides the physical memory location (Correct answer)
- A loop construct
- A Boolean expression
Correct answer: A naming abstraction that hides the physical memory location
Variable names are abstractions over physical memory addresses, making code readable and writable.
Question 7: Which of the following scenarios demonstrates abstraction being used to solve a problem?
- A programmer memorizes all 10,000 lines of a library's source code before using it
- A programmer calls `displayMap(city)` without knowing how the map is rendered (Correct answer)
- A programmer avoids using functions to keep code in one place
- A programmer uses only global variables to share data
Correct answer: A programmer calls `displayMap(city)` without knowing how the map is rendered
Calling `displayMap()` without knowing the rendering details is a direct application of abstraction.
Which of the following is NOT a benefit of using abstractions in programming?