Skip to content

Instantly share code, notes, and snippets.

@CompSciRocks
Last active November 27, 2018 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CompSciRocks/fc162d139a2167b14b310c73c1f3a782 to your computer and use it in GitHub Desktop.
Save CompSciRocks/fc162d139a2167b14b310c73c1f3a782 to your computer and use it in GitHub Desktop.
Solution for Pet free response question on 2004 AP Computer Science Exam - https://compsci.rocks/pet-solution/
public class Cat extends Pet {
public Cat(String name) {
super(name);
}
public String speak() {
return "meow";
}
}
public void allSpeak() {
for (Object o: petList) {
Pet p = (Pet)o;
p.speak();
}
}
public class LoudDog extends Dog {
public LoudDog(String name) {
super(name);
}
public String speak() {
return super.speak() + super.speak();
}
}
public abstract class Pet {
private String myName;
public Pet(String name) {}
public String getName() {}
public abstract String speak();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment