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 exception is thrown when a numeric string cannot be converted to a number?
What will be the output? public class Demo { public static void main(String[] args) { try { System.out.println("A"); throw new Exception("Test"); System.out.println("B"); } catch (Exception e) { System.out.println("C"); } } }
Which of the following exceptions is a checked exception in Java?
What is the correct syntax for declaring multiple exceptions in a method signature?
In Java exception handling, what is the purpose of the finally block?
What is the difference between 'throw' and 'throws' keywords in Java?
Which exception is thrown when a method argument is null but shouldn't be?
What happens when an unchecked exception is not caught?
Which exception is thrown when attempting to access an index outside the bounds of an array?
Consider a method signature: public void readFile() throws IOException. Which statement is correct?
Which of the following statements about try-catch-finally blocks is correct?
What is the output of the following code? public class ExceptionTest { public static void main(String[] args) { try { int x = ; } catch (ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); } } }
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"); }