Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 1: Exception Handling

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is an Exception in Java?

a)

An error that occurs during runtime

b)

An error that occurs during compilation

c)

A warning issued by the compiler

d)

A type of loop

2.

Which keyword is used to handle exceptions in Java?

a)

throws

b)

throw

c)

try

d)

catch

3.

What is the purpose of "try" block in exception handling?

a)

It catches exceptions and handles them

b)

It specifies the exception type

c)

It contains the code that might throw an exception

d)

It specifies the exception message

4.

In Java, can a method declare multiple exceptions using the "throws" keyword?

a)

Only if the method is marked as "static"

b)

Yes, a method can declare multiple exception separated by commas

c)

Only if the exceptions are marked as "final"

d)

Only if the method is marked as "final"

5.

What is the purpose of "catch" block in exception handling?

a)

It specifies the exception message

b)

It specifies the exception type

c)

It catches the exceptions and handles them

d)

It contains the code that might throw an exception

6.

In Java, can a "catch" block catch multiple exceptions?

a)

No, a "catch" block can only catch one exception

b)

Only if the "catch" block is marked as "static"

c)

Only if the exceptions are marked as "final"

d)

Yes, a "catch" block can catch multiple exceptions using the pipe (|) symbol

7.

What is the purpose of the "throw" keyword in Java exception handling?

a)

To explicitly throw an exception

b)

To catch exceptions

c)

To specify exception types

d)

To declare a method as "throws"

8.

In Java, can a method throw any checked exception without declaring it using "throws"?

a)

Only if the exception is marked as "static"

b)

Only if the method is marked as "final"

c)

No, a method can declare checked exceptions using the "throws" keyword

d)

Yes, a method can throw any checked exception without declaration

9.

What is the purpose of the "throws" keyword in Java method declaration?

a)

To indicate that the method will throw an unchecked exception

b)

To specify the exception message

c)

To indicate that the method may throw a checked exception

d)

To specify the exception type

10.

What is the result of the following code snippet?

try {

int[] arr = new int[5];

int value = arr[10];

} catch (ArrayIndexOutOfBoundsException e) {

System.out.println("Exception caught!");

}

a)

Compilation error

b)

Exception caught!

c)

Runtime exception

d)

Bounds exception

11.

In Java, which type of exceptions are checked at compile time?

a)

Custom exceptions

b)

Runtime exceptions

c)

Checked exceptions

d)

Unchecked exceptions

12.

What is the result of the following code snippet?

try {

int num=10/0;

} catch (ArithmeticException e) {

System.out.println("Arithmetic Exception!");

} catch ( Exception e) {

System.out.println("Exception!");

}

a)

Exception!

b)

No output

c)

Compilation error

d)

Arithmetic Exception!

13.

In Java, which type of exceptions are unchecked at compile-time?

a)

Unchecked exceptions

b)

Checked exceptions

c)

Runtime exceptions

d)

Custom exceptions

14.

What is the result of the following code snippet?

try {

String str = null;

System.out.println(str.length());

} catch (NullPointerException e) {

System.out.println("NullPointerException!");

} catch (Exception e) {

System.out.println("Exception!");

}

a)

Compilation error

b)

No output

c)

Exception!

d)

NullPointerException!

15.

In Java, can a "finally" block be used without a "try-catch" block?

a)

Yes, a "finally" block can be used independently

b)

Only if the "finally" block is marked as "static"

c)

No, a "finally" block must be associated with a "try-catch" block

d)

Only if the "finally" block is marked as "final"

16.

What is the purpose of the "finally" block in java exception handling?

a)

To throw exceptions explicitly

b)

To specify the code that must be executed regardless of whether an exception is thrown or caught

c)

To specify the exception type

d)

When an exception does not rise

17.

In Java, can a "finally" block be used without a "catch" block?

a)

Only if the "finally" block is marked as "final"

b)

Only if the "finally" block is marked as "static"

c)

Yes, a "finally" block can be used independently

d)

No, a "finally" block must be associated with a "catch" block

18.

What is the result of the following code snippet?

try {

int[] arr = new int[5];

int value = arr[2];

} catch (NullPointerException e) {

System.out.println("NullPointerException!");

} finally {

System.out.println("Finally Block!");

}

a)

No output

b)

NullPointerException!

c)

Compilation error

d)

Finally Block!

19.

In Java, can a "catch" block catch exceptions of a superclass type?

a)

Yes, a "catch" block can catch exceptions of a superclass type

b)

No, a "catch" block can only catch exceptions of the exact type

c)

Only if the superclass is marked as "final"

d)

Only if the subclass is marked as "static"

20.

What is the result of the following code snippet?

try {

int result = 10/0;

} catch (ArithmeticException e) {

System.out.println("ArithmeticException!");

} finally {

System.out.println("Finally Block!");

}

a)

No output

b)

Finally Block!

c)

ArithmeticException!

d)

ArithmeticException!

Finally Block!