CHAPTER 5 Review Question
CHAPTER 5 Review Question
A. protected
B. public
C. static
D. void
E. abstract
F. default
1: class Mammal {
3: System.out.print("Mammal");
4: }
5: }
7: public Platypus() {
8: System.out.print("Platypus");
9: }
12: }
13: }
A. Platypus
B. Mammal
C. PlatypusMammal
D. MammalPlatypus
3. Which of the following statements can be inserted in the blank line so that the code will compile
successfully? (Choose all that apply)
A. Frog
B. TurtleFrog
C. BrazilianHornedFrog
D. CanHop
E. Object
F. Long
4. Which statement(s) are correct about the following code? (Choose all that apply)
System.out.println("Rodent is chewing");
return 1;
return 2;
B. It fails to compile because the type of the exception the method throws is a subclass of the
type of exception the parent method throws.
D. It fails to compile because the method is protected in the parent class and public in the
subclass.
E. It fails to compile because of a static modifier mismatch between the two methods.
5. Which of the following may only be hidden and not overridden? (Choose all that apply)
D. static methods
E. public variables
F. private variables
1: interface HasExoskeleton {
3: }
6: }
9: }
7. Which of the following statements about polymorphism are true? (Choose all that apply)
A. A reference to an object may be cast to a subclass of the object without an explicit cast.
B. If a method takes a superclass of three objects, then any of those classes may be passed as a
parameter to the method.
C. A method that takes a parameter with type java.lang.Object will take any reference.
E. By defining a public instance method in the superclass, you guarantee that the specific
method will be called in the parent class at runtime.
5: return 13;
6: }
7: }
2: void fly();
3: }
4: interface HasWings {
6: }
8: }
F. The code will not compile because the class Falcon doesn’t implement the interface methods.
10. Which statements are true for both abstract classes and interfaces? (Choose all that apply)
11. What modifiers are assumed for all interface variables? (Choose all that apply)
A. public
B. protected
C. private
D. static
E. final
F. abstract
1: interface Nocturnal {
3: }
8: System.out.println(nocturnal.isBlind());
9: }
10: }
A. true
B. false
1: class Arthropod
.print("Arthropod"); }
3: }
8: spider.printName(4);
9: spider.printName(9.0);
10: }
11: }
A. SpiderArthropod
B. ArthropodSpider
C. SpiderSpider
D. ArthropodArthropod
14. Which statements are true about the following code? (Choose all that apply)
1: interface HasVocalCords {
3: }
6: }
C. A class that implements CanBark inherits both the makeSound() and bark() methods.
15. Which of the following is true about a concrete subclass? (Choose all that apply)
5: reptile.layEggs();
6: }
7: }
10: }
5: whale.dive();
6: }
7: }
A. Orca diving
18. What is the output of the following code? (Choose all that apply)
1: interface Aquatic {
3: }
8: System.out.println(new ClownFish().getNumberOfGills(-1));
9: }
10: }
A. 2
B. 4
C. 6
19. Which of the following statements can be inserted in the blank so that the code will compile
successfully? (Choose all that apply)
new SnakeHandler().setSnake( );
A. new Cobra()
B. new GardenSnake()
C. new Snake()
D. new Object()
E. new String("Snake")
F. null
5: bird.fly();
6: }
7: }
10: }
A. Bird is flying
B. Pelican is flying
E. The code will not compile because of line 9r((e) -> { String f = ""; return "Poof"; });