Unit 3 Cycle 1 Day 28: Comprehensive Unit 3 Review

Unit 3 Foundation (Cycle 1) Day 28 of 28 Foundation

Comprehensive Unit 3 Review

Section Mixed — Review: All Unit 3

Key Concept

This comprehensive Unit 3 review covers class design, encapsulation, constructors, inheritance, method overriding, and polymorphism. Unit 3 represents approximately 22-28% of the AP CSA exam and is the largest unit by weight. The most commonly tested concepts are: polymorphic method dispatch (compile-time vs runtime type), constructor chaining with super(), method overriding rules, and encapsulation principles. Mastering these topics is essential since they appear in both multiple-choice and free-response sections.

Consider the following code.

public class Item { private String name; private double price; public Item(String n, double p) { name = n; price = p; } public double getPrice() { return price; } public String toString() { return name + ": $" + price; } } Item[] items = {new Item("A", 5.0), new Item("B", 3.0), new Item("C", 7.0)}; double total = 0; for (Item item : items) { total += item.getPrice(); } System.out.println(total);

What is printed?

Answer: (A) 15.0

The enhanced for loop sums prices: 5.0 + 3.0 + 7.0 = 15.0.

Why Not the Others?

(B) 5.0 is only the first item's price.

(C) The code calls getPrice() (returns double), not toString().

(D) The code compiles. An array of objects with an enhanced for loop is valid.

Common Mistake

The enhanced for loop for (Item item : items) iterates over each Item object. Calling getPrice() on each returns the double price value.

AP Exam Tip

Enhanced for loops work with arrays of objects. Each iteration gives you the next object, on which you can call any public method.

Review this topic: Section Mixed — Review: All Unit 3 • Unit 3 Study Guide

More Practice

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.