Question 1 of 25
Hints left: 3
Q1
In Java, can a method throw any checked exception without declaring it using "throws"?
Q2
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!"); }
Q3
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!"); }
Q4
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) } }
Q5
In Java, which type of exceptions are checked at compile-time?
Q6
In Java, can a method declare "throws" for a checked exception that is not thrown in the method body?
Q7
In Java, can a method declare multiple exceptions using the "throws" keyword?
Q8
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!"); }
Q9
What is the purpose of the "try" block in exception handling?
Q10
What is the purpose of the "catch" block in exception handling?
Q11
In Java, can a "finally" block be used without a "catch" block?
Q12
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!"); }
Q13
In Java, can a "finally" block be used without a "try-catch" block?
Q14
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!"); }
Q15
In Java, can a "catch" block catch exceptions of a superclass type?
Q16
In Java, which type of exceptions are unchecked at compile-time?
Q17
What is the purpose of the "finally" block in Java exception handling?
Q18
In Java, can a method declare both "throws" and "throw" statements?
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
What is the purpose of the "throw" keyword in Java exception handling?
Q21
Which keyword is used to handle exceptions in Java?
Q22
What is the purpose of the "throws" keyword in Java method declaration?
Q23
What is an exception in Java?
Q24
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!"); }
Q25
In Java, can a "catch" block catch multiple exceptions?