GoConqr has a new look! Let us know what you think.

Quiz

Chapter 6 Exceptions

davidv 20 questions

Take the quiz

Questions in this quiz (20)

  1. 1Which of the following statements are true? (Choose all that apply)
    1. AA. Runtime exceptions are the same thing as checked exceptions.
    2. BB. Runtime exceptions are the same thing as unchecked exceptions.
    3. CC. You can declare only checked exceptions.
    4. DD. You can declare only unchecked exceptions.
    5. EE. You can handle only Exception subclasses.
  2. 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: }
    1. AA. On line 7, fill in throw
    2. BB. On line 7, fill in throws
    3. CC. On line 8, fill in throw
    4. DD. On line 8, fill in throw new
    5. EE. On line 8, fill in throws
    6. FF. On line 8, fill in throws new
  3. 3When are you required to use a finally block in a regular try statement (not a try-withresources)?
    1. AA. Never.
    2. BB. When the program code doesn’t terminate on its own.
    3. CC. When there are no catch blocks in a try statement.
    4. DD. When there is exactly one catch block in a try statement.
    5. EE. When there are two or more catch blocks in a try statement.
  4. 4Which exception will the following throw?
    Object obj = new Integer(3);
    String str = (String) obj;
    System.out.println(str);
    1. AA. ArrayIndexOutOfBoundsException
    2. BB. ClassCastException
    3. CC. IllegalArgumentException
    4. DD. NumberFormatException
    5. EE. None of the above.
  5. 5Which of the following exceptions are thrown by the JVM? (Choose all that apply)
    1. AA. ArrayIndexOutOfBoundsException
    2. BB. ExceptionInInitializerError
    3. CC. java.io.IOException
    4. DD. NullPointerException
    5. EE. NumberFormatException
  6. 6What will happen if you add the statement System.out.println(5 / 0); to a working
    main() method?
    1. AA. It will not compile.
    2. BB. It will not run.
    3. CC. It will run and throw an ArithmeticException.
    4. DD. It will run and throw an IllegalArgumentException.
    5. EE. None of the above.
  7. 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: }
    1. AA. AE
    2. BB. AEBCD
    3. CC. AEC
    4. DD. AECD
    5. EE. No output appears other than the stack trace.
  8. 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: }
    1. AA. -1
    2. BB. 0
    3. CC. done-1
    4. DD. done0
    5. EE. The code does not compile.
    6. FF. An uncaught exception is thrown.
  9. 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: } }
    1. AA. Starting up
    2. BB. Starting up Problem
    3. CC. Starting up Problem Shutting down
    4. DD. Starting up Shutting down
    5. EE. The code does not compile.
    6. FF. An uncaught exception is thrown.
  10. 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: } }
    1. AA. 12
    2. BB. 1234
    3. CC. 1235
    4. DD. 124
    5. EE. 1245
    6. FF. The code does not compile.
    7. GG. An uncaught exception is thrown.

Information

Description
OCA java 8 JAVA 8 Quiz on Chapter 6 Exceptions, created by davidv on 23/04/2016.
Author
davidv
Language
Español
Views
3
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?