iGET

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

Q.61Medium

Which of the following statements is true regarding exception constructors?

Q.62Medium

What is the output of multi-level exception chaining? public class ChainTest { public static void main(String[] args) { try { try { throw new IOException("IO Error"); } catch (IOException e) { throw new RuntimeException("Runtime Error", e); } } catch (RuntimeException e) { System.out.println(e.getCause().getClass().getSimpleName()); } } }

Q.63Medium

Which of the following best describes a custom exception in Java?

Q.64Medium

What will be the result of executing this code? public class MultiCatchTest { public static void main(String[] args) { try { int[] arr = {1, 2}; int x = arr[5]; } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { System.out.println("Array or Null Error"); } } }

Q.65Easy

Which method is used to print the stack trace of an exception?

Q.66Easy

Which of the following is NOT a subclass of Throwable?

Q.67Medium

Consider code that implements auto-closeable resources. What is the advantage of try-with-resources statement?

Q.68Hard

What will be printed for this code? public class ExceptionOrder { public static void main(String[] args) { try { try { throw new RuntimeException("Inner"); } catch (Exception e) { throw new IOException("Outer"); } } catch (IOException e) { System.out.println("Caught IOException"); } catch (RuntimeException e) { System.out.println("Caught RuntimeException"); } } }

Q.69Hard

Which of the following scenarios will NOT trigger a StackOverflowError?

Q.70Medium

What is the correct way to create a custom exception with cause chaining?

Q.71Hard

What happens when System.exit() is called inside try block?

Q.72Medium

Which interface must a class implement to work with try-with-resources?

Q.73Easy

In Java exception handling, which of the following statements is true about the finally block?

Q.74Easy

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);

Q.75Medium

In multi-catch block (Java 7+), which operator is used to catch multiple exceptions in a single catch clause?

Q.76Medium

What will be the output? try { throw new Exception("Test"); } catch(Exception e) { System.out.println("Caught"); throw new RuntimeException("New"); } finally { System.out.println("Finally"); }

Q.77Easy

Which exception is thrown when accessing an array element with an invalid index?

Q.78Easy

What is the correct syntax for declaring a method that throws a checked exception?

Q.79Medium

Consider the following exception hierarchy. Which statement will compile without error? class MyException extends Exception {} class MyRuntimeException extends RuntimeException {}

Q.80Easy

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"); }