Other 2004 FR Questions | FR other years | Be Prepared Home |
public class Cat extends Pet 1 { public Cat(String name) { super(name); 2 } public String speak() { return "meow"; } }Notes:
Part (b) public class LoudDog extends Dog 1 { public LoudDog(String name) { super(name); } public String speak() { String s = super.speak(); 2 return s + s; 3 } }Notes:
Part (c) // postcondition: for each pet in the kennel, its name followed // by the result of a call to its speak method // has been printed, one line per Pet public void allSpeak() { for (int i = 0; i < petList.size(); i++) { Pet pet = (Pet)petList.get(i); 1 System.out.println(pet.getName() + " " + pet.speak()); } }Notes:
|
Copyright © 2004 by Skylight Publishing
support@skylit.com