[ Pobierz całość w formacie PDF ]
8. System.out.print("End of file exception");
9. }
10. catch(FileNotFoundException e) {
11. System.out.print("File not found");
12. }
and given that EOFException and FileNotFoundException are both subclasses of
IOException, and further assuming this block of code is placed into a class, which statement is
most true concerning this code?
A. The code will not compile.
B. Code output:Start Hello world File Not Found.
C. Code output:Start Hello world End of file exception.
D. Code output:Start Hello world Catch Here File not found.
12. Given the following,
1. public class MyProgram {
2. public static void main(String args[]){
3. try {
4. System.out.print("Hello world ");
5. }
6. finally {
7. System.out.println("Finally executing ");
8. }
9. }
10. }
what is the result?
A. Nothing. The program will not compile because no exceptions are specified.
B. Nothing. The program will not compile because nocatchclauses are specified.
C. Hello world.
D. Hello world Finally executing
13. Given the following,
1. import java.io.*;
2. public class MyProgram {
3. public static void main(String args[]){
4. FileOutputStream out = null;
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
Chapter 4: Flow Control, Exceptions, and Assertions
70
5. try {
6. out = new FileOutputStream("test.txt");
7. out.write(122);
8. }
9. catch(IOException io) {
10. System.out.println("IO Error.");
11. }
12. finally {
13. out.close();
14. }
15. }
16. }
and given that all methods of class FileOutputStream, includingclose(),throw an
IOException, which of these is true? (Choose one.)
A. This program will compile successfully.
B. This program fails to compile due to an error at line 4.
C. This program fails to compile due to an error at line 6.
D. This program fails to compile due to an error at line 9.
E. This program fails to compile due to an error at line 13.
14. Given the following,
1. public class MyProgram {
2. public static void throwit() {
3. throw new RuntimeException();
4. }
5. public static void main(String args[]){
6. try {
7. System.out.println("Hello world ");
8. throwit();
9. System.out.println("Done with try block ");
10. }
11. finally {
12. System.out.println("Finally executing ");
13. }
14. }
15. }
which answer most closely indicates the behavior of the program?
A. The program will not compile.
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
71
B. The program will printHello world, then will print that a RuntimeException has
occurred, then will printDone with try block, and then will printFinally
executing.
C. The program will printHello world, then will print that a RuntimeException has
occurred, and then will printFinally executing.
D. The program will printHello world, then will printFinally executing, then
will print that aRuntimeExceptionhas occurred.
15. Given the following,
1. public class RTExcept {
2. public static void throwit () {
3. System.out.print("throwit ");
4. throw new RuntimeException();
5. }
6. public static void main(String [] args) {
7. try {
8. System.out.print("hello ");
9. throwit();
10. }
11. catch (Exception re ) {
12. System.out.print("caught ");
13. }
14. finally {
15. System.out.print("finally ");
16. }
17. System.out.println("after ");
18. }
19. }
what is the result?
A. hello throwit caught
B. Compilation fails
C. hello throwit RuntimeException caught after
D. hello throwit RuntimeException
E. hello throwit caught finally after
F. hello throwit caught finally after RuntimeException
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
Chapter 4: Flow Control, Exceptions, and Assertions
72
Assertions (Sun Objectives 2.5 and 2.6)
16. Which of the following statements is true?
A. In an assert statement, the expression after the colon ( : ) can be any Java expression.
B. If a switch block has no default, adding an assert default is considered appropriate.
C. In an assert statement, if the expression after the colon ( : ) does not have a value, the
assert s error message will be empty.
D. It is appropriate to handle assertion failures using acatchclause.
17. Which two of the following statements are true? (Choose two.)
A. It is sometimes good practice to throw an AssertionError explicitly.
B. It is good practice to place assertions where you think execution should never reach.
C. Privategetter()andsetter()methods should not use assertions to verify
arguments.
D. If an AssertionError is thrown in atry-catchblock, thefinallyblock will be
bypassed.
E. It is proper to handle assertion statement failures using a catch (AssertionException
ae) block.
18. Given the following,
1. public class Test {
2. public static int y;
3. public static void foo(int x) {
4. System.out.print("foo ");
5. y = x;
6. }
7. public static int bar(int z) {
8. System.out.print("bar ");
9. return y = z;
10. }
[ Pobierz całość w formacie PDF ]
-
Archiwum
- Strona pocz±tkowa
- Antologia SF Wolanie na Mlecznej Drodze
- Harlequin na śźyczenie 45.2 Re
- Feasey Steve WilkośÂak 04 Igrzyska demonów CaśÂośÂćÂ
- Cartland_Barbara_ _Raj_odnaleziony
- Haugen Peter Sekrety i skandale rodów królewskich
- Evangelium Vitae
- Wieczorem Fundacja Nowoczesna Polska E book
- Alex Archer Rogue Angel 03 The Sp
- Fiedler Arkady ZwierzćÂta mego śźycia
- Ian Fleming Bond 09 (1961) Thunderball
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- 18plusnowosci.xlx.pl