OCJP Preparation - Exception Handling - BEHIND JAVA

OCJP Preparation - Exception Handling

Share This

Given the program

what is the result?

  • A. 0.0
  • B. Compilation fails.
  • C. A ParseException is thrown by the parse method at runtime.
  • D. A NumberFormatException is thrown by the parse method at runtime.

Consider the following block of statements

Which statement is true if a ResourceException is thrown on line 6?

  • A. Line 9 will not execute.
  • B. The connection will not be retrieved in line 2.
  • C. The resource connection will not be closed on line 5.
  • D. The enclosing method will throw an exception to its caller.

Consider the following block of statement?

Under which three circumstances will the code on line 7 be executed? (Choose three.)

  • A. The instance gets garbage collected.
  • B. The code on line 3 throws an exception.
  • C. The code on line 5 throws an exception.
  • D. The code on line 1 throws an exception.
  • E. The code on line 3 executes successfully.

Given the program

What is the result?

  • A. Exception
  • B. A,B,Exception
  • C. Compilation fails because of an error in line 16.
  • D. Compilation fails because of an error in line 8.
  • E. A NullPointerException is thrown at runtime.

What is the output of following program?

  • A. end
  • B. Compilation fails.
  • C. exception end
  • D. exception test end
  • E. A Throwable is thrown by main.
  • F. An Exception is thrown by main
  • .

What is the output of following program?

  • A. Compilation fails.
  • B. pi is bigger than 3.
  • C. An exception occurs at runtime.
  • D. pi is bigger than 3. Have a nice day.
  • E. pi is not bigger than 3. Have a nice day.

What is the output of following program?

  • A. test
  • B. Exception
  • C. Compilation fails.
  • D. NullPointerException

What is the output of following program?

  • A. test end
  • B. Compilation fails.
  • C. test runtime end
  • D. test exception end
  • E. A Throwable is thrown by main at runtime.

Given the program

What is the result if a NullPointerException occurs on line 34?

  • A. c
  • B. a
  • C. ab
  • D. ac
  • E. bc
  • F. abc

What is the output of following program?

  • A. java.lang.StackOverflowError
  • B. java.lang.IllegalStateException
  • C. java.lang.ExceptionInInitializerError
  • D. java.lang.ArrayIndexOutOfBoundsException

Given the program

what is the output?

  • A. null
  • B. finally
  • C. null finally
  • D. Compilation fails.
  • E. finally exception

Given the program

Which two are true? (Choose two.)

  • A. Class A will not compile.
  • B. Line 16 can throw the unchecked exception TestException.
  • C. Line 15 can throw the unchecked exception TestException.
  • D. Line 16 will compile if the enclosing method throws a TestException.
  • E. Line 16 will compile if enclosed in a try block, where TestException is caught.

Given the program

Which, inserted independently at // insert code here, will compile, and produce the output? (Choose all that apply.)

  • A. String doFileStuff() { return "b"; }
  • B. String doFileStuff() throws IOException { return "b"; }
  • C. String doFileStuff(int x) throws IOException { return "b"; }
  • D. String doFileStuff() throws FileNotFoundException { return "b"; }
  • E. String doFileStuff() throws NumberFormatException { return "b"; }
  • F. String doFileStuff() throws NumberFormatException, FileNotFoundException { return "b"; }

Given the program

And the command-line invocations:

java Input
java Input 0

Which are true? (Choose all that apply.)

  • A. Line 6 is executed exactly 0 times.
  • B. Line 6 is executed exactly 1 time.
  • C. Line 6 is executed exactly 2 times.
  • D. The finally block is executed exactly 0 times.
  • E. The finally block is executed exactly 1 time.
  • F. The finally block is executed exactly 2 times.
  • G. Both invocations produce the same exceptions.
  • H. Each invocation produces a different exception.

Given the program

What is the result?

  • A. -
  • B. -c
  • C. -c2
  • D. -2c
  • E. -c22b
  • F. -2c2b
  • G. -2c2bc
  • H. Compilation fails.

Given:

try { int x = Integer.parseInt("two"); }

Which could be used to create an appropriate catch block? (Choose all that apply.)

  • A. ClassCastException
  • B. IllegalStateException
  • C. NumberFormatException
  • D. IllegalArgumentException
  • E. ExceptionInInitializerError
  • F. ArrayIndexOutOfBoundsException

Given the program

And the following three possible changes:

C1. Declare that main() throws an Exception.

C2. Declare that Ping.getInt() throws an Exception.

C3. Wrap the invocation of getInt() in a try / catch block.

Which change(s) allow the code to compile? (Choose all that apply.)

  • A. Just C1 is sufficient.
  • B. Just C2 is sufficient.
  • C. Just C3 is sufficient.
  • D. Both C1 and C2 are required.
  • E. Both C1 and C3 are required.
  • F. Both C2 and C3 are required.
  • G. All three changes are required.

Given the program

What is the result?

  • A. -ic of
  • B. -mf of
  • C. -mc mf
  • D. -ic mf of
  • E. -ic mc mf of
  • F. -ic mc of mf
  • G. Compilation fails.

Given the program

And the command-line invocation:

java Miner.java

What is the result?

  • A. null
  • B. null null
  • C. A ClassCastException is thrown.
  • D. A NullPointerException is thrown.
  • E. A NoClassDefFoundError is thrown.
  • F. An ArithmeticException is thrown.
  • G. An IllegalArgumentException is thrown.
  • H. An ArrayIndexOutOfBoundsException is thrown.

Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)

  • A. ClassCastException
  • B. IllegalStateException
  • C. NumberFormatException
  • D. IllegalArgumentException
  • E. ExceptionInInitializerError

No comments:

Post a Comment

Pages