pdf | do ÂściÂągnięcia | ebook | pobieranie | download
Pokrewne
- Strona Główna
- Charlaine Harris Grobowa tajemnica
- Child_Maureen_ _Trojaczki_Reilly_02_ _W_pulapce_namietnosci
- D414. Greene Jennifer Pokochaj swojego szeryfa
- Jack Williamson Eldren 02 Mazeway
- Lois McMaster Bujold 12 Komarr
- Konwicki Tadeusz MaćąĂ˘Â€Âša apokalipsa
- Wright Glover SśÂ‚uga niebios
- Moore Sean U Conan i szalony Bóg
- Guzek_Maciej_ _Trzeci_śÂšwiat
- test3
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- btsbydgoszcz.opx.pl
[ Pobierz całość w formacie PDF ]
and the second is a while loop, nested inside the do-while. The body of the do-while is only a
single statement brackets are not needed. You are assured that the while expression will be
evaluated at least once, followed by an evaluation of the do-while expression. Both expressions
are false and no output is produced.
A, B, D, and E are incorrect based on the program logic described above.
9. A. The program flows as follows:Iwill be incremented after the while loop is entered,
thenIwill be incremented (by zero) when the for loop is entered. The if statement evaluates
to false, and thecontinuestatement is never reached. Thebreakstatement tells the
JVM to break out of the outer loop, at which pointIis printed and the fragment is done.
B, C, and D are incorrect based on the program logic described above.
10. C. The code will not compile because acontinuestatement can only occur in a
looping construct. If this syntax were legal, the combination of thecontinueand the if
statements would create a kludgey kind of loop, but the compiler will force you to write
cleaner code than this.
A, B, and D are incorrect based on the program logic described above.
Exceptions (Sun Objectives 2.3 and 2.4)
11. A. Line 6 will cause a compiler error. The only legal statements aftertryblocks are either
catchorfinallystatements.
B, C, and D are incorrect based on the program logic described above. If line 6 was
removed, the code would compile and the correct answer would be B.
12. D.Finallyclauses are always executed. The program will first execute thetryblock,
printingHello world, and will then execute thefinallyblock, printingFinally
executing.
A, B, and C are incorrect based on the program logic described above. Remember that
either acatchor afinallystatement must follow atry. Since the finally is present,
the catch is not required.
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 4
Composite Default screen
Self Test Answers
77
13. E. Any method (in this case, themain()method) that throws a checked exception (in
this case,out.close()) must be called within atryclause, or the method must declare
that it throws the exception. Eithermain()must declare that it throws an exception, or the
call toout.close()in thefinallyblock must fall inside a (in this case nested)
try-catchblock.
A, B, C, and D are incorrect based on the program logic described above.
14. D. Once the program throws a RuntimeException (in thethrowit()method) that
is not caught, thefinallyblock will be executed and the program will be terminated. If a
method does not handle an exception, thefinallyblock is executed before the exception
is propagated.
A, B, and C are incorrect based on the program logic described above.
15. E. Themain()method properly catches and handles the RuntimeException in the
catchblock, finally runs (as it always does), and then the code returns to normal.
A, B, C, D, and F are incorrect based on the program logic described above. Remember
that properly handled exceptions do not cause the program to stop executing.
Assertions (Sun Objectives 2.5 and 2.6)
16. B. Adding an assertion statement to aswitchstatement that previously had no default
case is considered an excellent use of the assert mechanism.
A is incorrect because only Java expressions that return a value can be used. For instance, a
method that returnsvoidis illegal. C is incorrect because the expression after the colon must
have a value. D is incorrect because assertions throw errors and not exceptions, and assertion
errors do cause program termination and should not be handled.
17. A and B. A is correct because it is sometimes advisable to thrown an assertion error even
if assertions have been disabled. B is correct. One of the most common uses ofassert
statements in debugging is to verify that locations in code that have been designed to be
unreachable are in fact never reached.
C is incorrect because it is considered appropriate to check argument values in private
methods using assertions. D is incorrect; finally is never bypassed. E is incorrect because
AssertionErrors should never be handled.
18. E. Thefoo()method returnsvoid. It is a perfectly acceptable method, but because it
returnsvoidit cannot be used in an assert statement, so line 14 will not compile.
A, B, C, D, and F are incorrect based on the program logic described above.
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 4
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 4
Composite Default screen
Chapter 4: Flow Control, Exceptions, and Assertions
78
19. C and D. C is true because multiple VM flags can be used on a single invocation of a Java
program. D is true, these are all valid flags for the VM.
A is incorrect because at runtime assertions are ignored by default. B is incorrect because as
[ Pobierz całość w formacie PDF ]