AP Computer Science A Quiz
20 questions · no time limit
0:00
CLASS CREATION
Question 1 of 20
No time limit
Current
Answered
Flagged
Not seen
A game studio is building a level editor alongside its game, so designers can add new enemies without changing core engine code. The class design includes GameCharacter, Enemy, and Level. GameCharacter stores private position and health and provides move and takeDamage methods. Enemy extends GameCharacter and adds a method chooseAction(Level level). Specific enemies like SlimeEnemy and BossEnemy extend Enemy and override chooseAction differently. Level keeps a list of Enemy objects and calls chooseAction on each enemy during update(), without checking the enemy's exact class. This is polymorphism: Level interacts with the Enemy type, and each subclass decides its behavior. Encapsulation prevents Level from directly changing health, so damage must go through takeDamage, which enforces nonnegative health. The team finds this design easier to maintain because adding a new enemy only requires a new subclass; Level's update loop stays the same. It also improves readability by keeping enemy logic inside enemy classes rather than in Level. Performance remains manageable because the update loop avoids a long chain of type checks, which would grow as more enemy types are added. Based on the scenario, how does polymorphism in the described classes benefit the program?
YOUR PROGRESS
20
QUESTIONS
Ready when you are
Answer in any order. Your progress shows here as you go.
QUESTIONS
KEYBOARD
Pick an answer ABCD
Next question ↵→
Previous ←
Flag for review F
Answers save as you go · flagged questions come back at the end