2004 AP CSA FRQ 2: Pet - Complete Solution

2004 AP CSA FRQ 2: Pet

Topic: Inheritance & Polymorphism

Skills Tested: Abstract classes, subclass creation, super keyword, method overriding

Curriculum Alignment: Unit 3 (Class Creation) (2025-2026 AP CSA)

Points: 9 | Time Estimate: ~22 minutes

Part (a)

Write the complete Cat class that extends Pet. The speak method returns "meow".

Try It First! Attempt to solve this part before viewing the solution. Use the concepts: Abstract classes.

Solution

public class Cat extends Pet
{
    public Cat(String name)
    {
        super(name);
    }
    
    public String speak()
    {
        return "meow";
    }
}

Part (b)

Write the complete LoudDog class that extends Dog. The speak method returns the dog sound repeated twice.

Solution

public class LoudDog extends Dog
{
    public LoudDog(String name)
    {
        super(name);
    }
    
    public String speak()
    {
        return super.speak() + super.speak();
    }
}

Part (c)

Write the allSpeak method that prints each pet's name followed by its speak output.

Solution

public void allSpeak()
{
    for (int i = 0; i < petList.size(); i++)
    {
        Pet p = (Pet) petList.get(i);
        System.out.println(p.getName() + " " + p.speak());
    }
}

Key Concepts

Use super(name) to call the parent constructor
Use super.speak() to call the parent's method
Polymorphism allows calling speak() on any Pet subclass
Each subclass provides its own implementation of speak()

Common Mistakes to Avoid

Forgetting to call super() in the constructor
Trying to access private parent fields directly
Not using super.speak() in LoudDog
Forgetting the extends keyword

Scoring Guidelines

Total Points: 9

Points are awarded for:

  • Correct loop structure and bounds
  • Proper method calls and return statements
  • Correct conditional logic
  • Handling edge cases appropriately

Partial credit is available for demonstrating understanding even with minor syntax errors.

Official College Board Resources

About the Author: Tanner Crow is a certified AP Computer Science teacher with 11+ years of experience helping students succeed on the AP CSA exam.

Last updated: January 2026

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]