Last active
November 27, 2018 20:21
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cat extends Pet { | |
public Cat(String name) { | |
super(name); | |
} | |
public String speak() { | |
return "meow"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void allSpeak() { | |
for (Object o: petList) { | |
Pet p = (Pet)o; | |
p.speak(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoudDog extends Dog { | |
public LoudDog(String name) { | |
super(name); | |
} | |
public String speak() { | |
return super.speak() + super.speak(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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