Vidyalelo
Java Programming · all questions

Exceptions
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

115

Questions

1/6

Page

Pick an option on a question to see the right answer and solution.

What is an exception in Java?

Select an option to see the answer and solution.

Which keyword is used to handle exceptions in Java?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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!");
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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!");
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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!");
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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!");
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the result of the following code snippet?

try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Arithmetic Exception!");
} finally {
System.out.println("Finally Block!");
}

Select an option to see the answer and solution.