What is the result? (Choose all that apply.)

A. An exception is thrown at runtime

B. The code compiles and runs with no output

C. Compilation fails with an error at line 8

D. Compilation fails with an error at line 9

E. Compilation fails with an error at line 12

F. Compilation fails with an error at line 13

Answer:

 

Image A is correct, a ClassCastException will be thrown when the code attempts to downcast a Tree to a Redwood.

 

Image B, C, D, E, and F are incorrect based on the above information.
(Objective 5.2)

 

10. Given:

Image

 

What is the result?

A. fa fa

B. fa la

C. la la

D. Compilation fails

E. An exception is thrown at runtime

Answer:

 

Image B is correct. The code is correct, but polymorphism doesn't apply to static methods.

 

Image A, C, D, and E are incorrect based on the above information.
(Objective 5.2)

 

11. Given:

Image

 

What is the result?

A. subsub

B. sub subsub

C. alpha subsub

D. alpha sub subsub

E. Compilation fails

F. An exception is thrown at runtime

Answer:

 

Image C is correct. Watch out, SubSubAlpha extends Alpha! Since the code doesn't attempt to make a SubAlpha, the private constructor in SubAlpha is okay.

 

Image A, B, D, E, and F are incorrect based on the above information.
(Objective 5.3)

 

12. Given:

Image

 

What is the result?

A. h hn x

B. hn x h

C. b h hn x

D. b hn x h

E. bn x h hn x

F. b bn x h hn x

G. bn x b h hn x

H. Compilation fails

Answer:

 

Image C is correct. Remember that constructors call their superclass constructors, which execute first, and that constructors can be overloaded.

 

Image A, B, D, E, F, G, and H are incorrect based on the above information.
(Objectives 1.6, 5.4)

 

13. Given:

Image

 

What is the result?

A. furry bray

B. stripes bray

C. furry generic noise

D. stripes generic noise

E. Compilation fails

F. An exception is thrown at runtime

Answer:

 

Image A is correct. Polymorphism is only for instance methods.

 

Image B, C, D, E, and F are incorrect based on the above information.
(Objectives 1.5, 5.4)

 

14. You're designing a new online board game in which Floozels are a type of Jammers, Jammers can have Quizels, Quizels are a type of Klakker, and Floozels can have several Floozets. Which of the following fragments represent this design? (Choose all that apply.)

Image

 

Answer:

 

Image A and C are correct. The phrase "type of" indicates an "is-a" relationship (extends or implements), and the phrase "have" is of course a "has-a" relationship (usually instance variables).

 

Image B and D are incorrect based on the above information.
(Objective 5.5)

 

15. Given:

Image

 

What is the result?

A. -124

B. -134

C. -424

D. -434

E. -444

F. Compilation fails

Answer:

 

Image D is correct. In general, overloaded var-args methods are chosen last. Remember that arrays are objects. Finally, an int can be boxed to an Integer and then "widened" to an Object.

 

Image A, B, C, E, and F are incorrect based on the above information.
(Objective 1.5)

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.249.90