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
Which of the following is a checked exception in Java?
What is the output of the following code? int x = 10; try { x = x / 0; } catch(ArithmeticException e) { x = x + 5; } finally { x = x * 2; } System.out.println(x);
Which exception is thrown when a method receives an illegal or inappropriate argument?
Can you have a try block without a catch block in Java?
What will be the output? try { throw new Exception("Test"); } catch(Exception e) { System.out.println("Caught"); } finally { System.out.println("Finally"); }
Which of the following is NOT a subclass of Throwable in Java?
What is the output of multiple catch blocks? try { int[] arr = {1, 2, 3}; System.out.println(arr[5]); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Index"); } catch(Exception e) { System.out.println("Exception"); }
Which exception is thrown when trying to access a method of a null object?
Analyze the code: try { return 5; } finally { return 10; } What will be returned?
Which of the following exceptions is a checked exception?
What happens if an exception is thrown in the finally block?
Which statement about try-with-resources is TRUE?
What is the output? try { int x = ; } catch(Exception e) { System.out.println("Caught"); } catch(ArithmeticException ae) { System.out.println("Arithmetic"); }
Which exception is thrown when a string cannot be converted to a number?
Analyze this code: public void test() throws IOException { // method body } What does 'throws' indicate?
Which exception hierarchy is correct in Java?
What will happen if you don't catch a checked exception?
Analyze the nested try-catch: try { try { int x = ; } catch(NullPointerException e) { System.out.println("Inner"); } } catch(ArithmeticException e) { System.out.println("Outer"); }
What is the output of this code? public class Test { public static void main(String[] args) { try { int[] arr = {1, 2}; System.out.println(arr[5]); } catch (Exception e) { System.out.println("Caught"); } } }
In Java exception handling, what is the order of execution in try-finally-catch block?