Unit 3 Cycle 1 Day 28: Comprehensive Unit 3 Review
Share
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.
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.