Question 1 of 25
Hints left: 3
Q1
In Java, can a "finally" block be used without a "catch" block?
Q2
What is an exception in Java?
Q3
Which keyword is used to handle exceptions in Java?
Q4
In Java, can a method throw any checked exception without declaring it using "throws"?
Q5
What is the result of the following code snippet? try { String str = "Java"; int num = Integer.parseInt(str); } catch (NumberFormatException e) { System.out.println("NumberFormatException!"); } catch (Exception e) { System.out.println("Exception!"); } finally { System.out.println("Finally Block!"); }
Q6
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!"); }
Q7
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!"); }
Q8
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!"); }
Q9
What is the purpose of the "catch" block in exception handling?
Q10
In Java, can a "catch" block catch exceptions of a superclass type?
Q11
What is the purpose of the "try" block in exception handling?
Q12
In Java, can a method declare both "throws" and "throw" statements?
Q13
In Java, can a method declare "throws" for a checked exception that is not thrown in the method body?
Q14
What is the purpose of the "throws" keyword in Java method declaration?
Q15
In Java, can a "catch" block catch multiple exceptions?
Q16
In Java, which type of exceptions are checked at compile-time?
Q17
In Java, which type of exceptions are unchecked at compile-time?
Q18
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!"); }
Q19
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!"); }
Q20
In Java, can a method declare multiple exceptions using the "throws" keyword?
Q21
What is the purpose of the "throw" keyword in Java exception handling?
Q22
In Java, can a "finally" block be used without a "try-catch" block?
Q23
What will be the output of the following Java code? class A { public int i; public int j; A() { i = 1; j = 2; } } class B extends A { int a; B() { super(); } } class super_use { public static void main(String args[]) { B obj = new B(); System.out.println(obj.i + " " + obj.j) } }
Q24
What is the purpose of the "finally" block in Java exception handling?
Q25
What is the result of the following code snippet? try { throw new NullPointerException(); } catch (ArithmeticException e) { System.out.println("Arithmetic Exception!"); } catch (NullPointerException e) { System.out.println("NullPointerException!"); }