Java Programming - MCQ Practice Questions
Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
958 questions | 100% Free
What will be the output? public class Test { public static void main(String[] args) { try { throw new Exception("Test"); } catch (Exception e) { System.out.println("1"); } catch (Exception e) { System.out.println("2"); } } }
Which method is used to print the stack trace of an exception?
Which of the following is NOT a subclass of Throwable?
In Java exception handling, which of the following statements is true about the finally block?
What is the output of the following code? int x = 10; try { x = x / 0; } catch (ArithmeticException e) { x = 20; } finally { x = 30; } System.out.println(x);
Which exception is thrown when accessing an array element with an invalid index?
What is the correct syntax for declaring a method that throws a checked exception?
What will happen when the following code is executed? try { int[] arr = {1, 2, 3}; System.out.println(arr[5]); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Exception caught"); }
What is the output of the following code? try { int x = ; } catch(ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); } System.out.println("After");
What is the primary difference between throw and throws in Java exception handling?