Quiz
Chapter 6 Exceptions
Erstelle ein kostenloses Konto, um dieses Quiz zu beenden
Speichere deinen Fortschritt und sieh dir dein Endergebnis an.
oder mit deiner E-Mail registrieren
Schon ein Konto? Anmelden
Fragen in diesem Quiz (20)
1Which of the following statements are true? (Choose all that apply)
- AA. Runtime exceptions are the same thing as checked exceptions.
- BB. Runtime exceptions are the same thing as unchecked exceptions.
- CC. You can declare only checked exceptions.
- DD. You can declare only unchecked exceptions.
- EE. You can handle only Exception subclasses.
2Which of the following pairs fill in the blanks to make this code compile? (Choose all that
apply)
7: public void ohNo() _____ Exception {
8: _____________ Exception();
9: }- AA. On line 7, fill in throw
- BB. On line 7, fill in throws
- CC. On line 8, fill in throw
- DD. On line 8, fill in throw new
- EE. On line 8, fill in throws
- FF. On line 8, fill in throws new
3When are you required to use a finally block in a regular try statement (not a try-withresources)?
- AA. Never.
- BB. When the program code doesn’t terminate on its own.
- CC. When there are no catch blocks in a try statement.
- DD. When there is exactly one catch block in a try statement.
- EE. When there are two or more catch blocks in a try statement.
4Which exception will the following throw?
Object obj = new Integer(3);
String str = (String) obj;
System.out.println(str);- AA. ArrayIndexOutOfBoundsException
- BB. ClassCastException
- CC. IllegalArgumentException
- DD. NumberFormatException
- EE. None of the above.
5Which of the following exceptions are thrown by the JVM? (Choose all that apply)
- AA. ArrayIndexOutOfBoundsException
- BB. ExceptionInInitializerError
- CC. java.io.IOException
- DD. NullPointerException
- EE. NumberFormatException
6What will happen if you add the statement System.out.println(5 / 0); to a working
main() method?- AA. It will not compile.
- BB. It will not run.
- CC. It will run and throw an ArithmeticException.
- DD. It will run and throw an IllegalArgumentException.
- EE. None of the above.
7What is printed besides the stack trace caused by the NullPointerException from line 16?
1: public class DoSomething {
2: public void go() {
3: System.out.print("A");
4: try {
5: stop();
6: } catch (ArithmeticException e) {
7: System.out.print("B");
8: } finally {
9: System.out.print("C");
10: }
11: System.out.print("D");
12: }
13: public void stop() {
14: System.out.print("E");
15: Object x = null;
16: x.toString();
17: System.out.print("F");
18: }
19: public static void main(String[] args) {
20: new DoSomething().go();
21: }
22: }- AA. AE
- BB. AEBCD
- CC. AEC
- DD. AECD
- EE. No output appears other than the stack trace.
8What is the output of the following snippet, assuming a and b are both 0?
3: try {
4: return a / b;
5: } catch (RuntimeException e) {
6: return -1;
7: } catch (ArithmeticException e) {
8: return 0;
9: } finally {
10: System.out.print("done");
11: }- AA. -1
- BB. 0
- CC. done-1
- DD. done0
- EE. The code does not compile.
- FF. An uncaught exception is thrown.
9What is the output of the following program?
1: public class Laptop {
2: public void start() {
3: try {
4: System.out.print("Starting up ");
5: throw new Exception();
6: } catch (Exception e) {
7: System.out.print("Problem ");
8: System.exit(0);
9: } finally {
10: System.out.print("Shutting down ");
11: }
12: }
13: public static void main(String[] args) {
14: new Laptop().start();
15: } }- AA. Starting up
- BB. Starting up Problem
- CC. Starting up Problem Shutting down
- DD. Starting up Shutting down
- EE. The code does not compile.
- FF. An uncaught exception is thrown.
10What is the output of the following program?
1: public class Dog {
2: public String name;
3: public void parseName() {
4: System.out.print("1");
5: try {
6: System.out.print("2");
7: int x = Integer.parseInt(name);
8: System.out.print("3");
9: } catch (NumberFormatException e) {
10: System.out.print("4");
11: }
12: }
13: public static void main(String[] args) {
14: Dog leroy = new Dog();
15: leroy.name = "Leroy";
16: leroy.parseName();
17: System.out.print("5");
18: } }- AA. 12
- BB. 1234
- CC. 1235
- DD. 124
- EE. 1245
- FF. The code does not compile.
- GG. An uncaught exception is thrown.
11What is the output of the following program?
1: public class Cat {
2: public String name;
3: public void parseName() {
4: System.out.print("1");
5: try {
6: System.out.print("2");
7: int x = Integer.parseInt(name);
8: System.out.print("3");
9: } catch (NullPointerException e) {
10: System.out.print("4");
11: }
12: System.out.print("5");
13: }
14: public static void main(String[] args) {
15: Cat leo = new Cat();
16: leo.name = "Leo";
17: leo.parseName();
18: System.out.print("6");
19: }
20: }- AA. 12, followed by a stack trace for a NumberFormatException
- BB. 124, followed by a stack trace for a NumberFormatException
- CC. 12456
- DD. 12456
- EE. 1256, followed by a stack trace for a NumberFormatException
- FF. The code does not compile.
- GG. An uncaught exception is thrown.
12What is printed by the following? (Choose all that apply)
1: public class Mouse {
2: public String name;
3: public void run() {
4: System.out.print("1");
5: try {
6: System.out.print("2");
7: name.toString();
8: System.out.print("3");
9: } catch (NullPointerException e) {
10: System.out.print("4");
11: throw e;
12: }
13: System.out.print("5");
14: }
15: public static void main(String[] args) {
16: Mouse jerry = new Mouse();
17: jerry.run();
18: System.out.print("6");
19: } }- AA. 1
- BB. 2
- CC. 3
- DD. 4
- EE. 5
- FF. 6
- GG. The stack trace for a NullPointerException
13Which of the following statements are true? (Choose all that apply)
- AA. You can declare a method with Exception as the return type.
- BB. You can declare any subclass of Error in the throws part of a method declaration.
- CC. You can declare any subclass of Exception in the throws part of a method declaration.
- DD. You can declare any subclass of Object in the throws part of a method declaration.
- EE. You can declare any subclass of RuntimeException in the throws part of a method declaration.
14Which of the following can be inserted on line 8 to make this code compile? (Choose all
that apply)
7: public void ohNo() throws IOException {
8: // INSERT CODE HERE
9: }- AA. System.out.println("it's ok");
- BB. throw new Exception();
- CC. throw new IllegalArgumentException();
- DD. throw new java.io.IOException();
- EE. throw new RuntimeException();
15Which of the following are unchecked exceptions? (Choose all that apply)
- AA. ArrayIndexOutOfBoundsException
- BB. IllegalArgumentException
- CC. IOException
- DD. NumberFormatException
- EE. Any exception that extends RuntimeException
- FF. Any exception that extends Exception
16Which scenario is the best use of an exception?
- AA. An element is not found when searching a list.
- BB. An unexpected parameter is passed into a method.
- CC. The computer caught fire.
- DD. You want to loop through a list.
- EE. You don’t know how to code a method.
17Which of the following can be inserted into Lion to make this code compile? (Choose all
that apply)
class HasSoreThroatException extends Exception {}
class TiredException extends RuntimeException {}
interface Roar {
void roar() throws HasSoreThroatException;
}
class Lion implements Roar {// INSERT CODE HERE
}- AA. public void roar(){}
- BB. public void roar() throws Exception{}
- CC. public void roar() throws HasSoreThroatException{}
- DD. public void roar() throws IllegalArgumentException{}
- EE. public void roar() throws TiredException{}
18Which of the following are true? (Choose all that apply)
- AA. Checked exceptions are allowed to be handled or declared.
- BB. Checked exceptions are required to be handled or declared.
- CC. Errors are allowed to be handled or declared.
- DD. Errors are required to be handled or declared.
- EE. Runtime exceptions are allowed to be handled or declared.
- FF. Runtime exceptions are required to be handled or declared.
19Which of the following can be inserted in the blank to make the code compile? (Choose all
that apply)
public static void main(String[] args) {
try {
System.out.println("work real hard");
} catch ( e) {
} catch (RuntimeException e) {
}
}- AA. Exception
- BB. IOException
- CC. IllegalArgumentException
- DD. RuntimeException
- EE. StackOverflowError
- FF. None of the above.
20What does the output of the following contain? (Choose all that apply)
12: public static void main(String[] args) {
13: System.out.print("a");
14: try {
15: System.out.print("b");
16: throw new IllegalArgumentException();
17: } catch (IllegalArgumentException e) {
18: System.out.print("c");
19: throw new RuntimeException("1");
20: } catch (RuntimeException e) {
21: System.out.print("d");
22: throw new RuntimeException("2");
23: } finally {
24: System.out.print("e");
25: throw new RuntimeException("3");
26: }
27: }- AA. abce
- BB. abde
- CC. An exception with the message set to "1"
- DD. An exception with the message set to "2"
- EE. An exception with the message set to "3"
- FF. Nothing; the code does not compile.
Informationen
- Beschreibung
- OCA java 8 JAVA 8 Quiz am Chapter 6 Exceptions, erstellt von davidv am 23/04/2016.
- Autor
- davidv
- Sprache
- Español
- Aufrufe
- 3
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz