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.21Medium

Which statement is TRUE about exception propagation in Java?

Q.22Medium

What will be the behavior if an exception is thrown in the finally block?

Q.23Medium

Which statement about try-with-resources (introduced in Java 7) is correct?

Q.24Medium

Consider this code snippet. What will happen? try { int x = ; } catch (NullPointerException e) { System.out.println("Caught NPE"); }

Q.25Medium

What is the output of this code? public class ExceptionDemo { public static void main(String[] args) { try { int arr[] = new int[2]; arr[5] = 10; } catch (Exception e) { System.out.println("Exception caught"); } finally { System.out.println("Finally block"); } } }

Q.26Medium

What happens if you use 'return' statement inside a finally block?

Q.27Medium

What will be printed? public class Test { public static void main(String[] args) { try { System.out.println("In try"); return; } catch (Exception e) { System.out.println("In catch"); } finally { System.out.println("In finally"); } } }

Q.28Medium

What is the output of exception chaining in Java?

Q.29Medium

Which method is used to get the exception that caused the current exception in Java?

Q.30Medium

Which exception is thrown when a thread tries to acquire a monitor that is already locked?

Q.31Medium

Consider the following code. What will be printed? public class FinallyTest { public static int getValue() { try { return 10; } finally { System.out.println("Finally"); } } public static void main(String[] args) { System.out.println(getValue()); } }

Q.32Medium

Which of the following statements is true regarding exception constructors?

Q.33Medium

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.34Medium

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

Q.35Medium

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.36Medium

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

Q.37Medium

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

Q.38Medium

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

Q.39Medium

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

Q.40Medium

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