|
|
Authorized user can see question and answers. Please log in or sign up. 
|
#85. Given: 11. class Automobile { 12. public void drive () { System. out. print("go forward "); } 13. } 14. class Ferrari extends Automobile { 15. public void drive () { System. out. print("go fast "); } 16. } 18. public static void main (String[] args ) { 19. Automobile[] autos = { new Automobile(), new Ferrari() }; 20. for (int x = 0; x < autos.length; x++) 21. autos[x].drive(); 22. } 23. }
What is the result?
Show comments for this question (0)
Add comments
Link to this question
|
|
#89. Exhibit: 1. interface Drinkable { 2. void drink(); 3. } 1. class Tea implements Drinkable { 2. public void drink () { System. out. print("Drinking tea..."); } 3. } 1. class Coffee implements Drinkable { 2. public void drink () { System. out. print("Drinking coffee..."); } 3. } 1. public class TestDrink { 2. static boolean teaFlag; 3. public static Drinkable getDrinkable() { 4. if (teaFlag) { 5. return new Tea(); 6. } else { 7. return new Coffee(); 8. } 9. } 10. // more code that sets the value of the teaFlag boolean 11. } 1. public class DrinkableFactory { 2. static boolean teaFlag; 3. public static Drinkable getDrinkable(){ 4. if (teaFlag) { 5. return new Tea(); 6. } else { 7. return new Coffee(); 8. } 9. } 10. // more code that sets the value of the teaFlag boolean 11. }
Which, inserted at line 3 of the TestDrink class, demonstrates the "program to an interface" principle?
Show comments for this question (0)
Add comments
Link to this question
|
|
|
|
gen. 0.222
|
Server date 05:51 10-01-2009
|
Developed by Zip © 2006
|
|
 |
|
|