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
Analyze the code: try { return 5; } finally { return 10; } What will be returned?
What happens if an exception is thrown in the finally block?
Analyze the nested try-catch: try { try { int x = ; } catch(NullPointerException e) { System.out.println("Inner"); } } catch(ArithmeticException e) { System.out.println("Outer"); }
What will be printed? public class ExceptionTest { public static void main(String[] args) { try { testMethod(); } catch (Exception e) { System.out.println("Caught"); } } public static void testMethod() { try { throw new RuntimeException("Error"); } finally { System.out.println("Finally"); } } }
Which of the following is NOT a characteristic of Exception class in Java?
Which of the following cannot throw a checked exception without being declared in throws clause?
What is the execution order in try-catch-finally for nested exception handling?
What is suppressed exception in Java (introduced in Java 7)?
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"); } } }
Which of the following scenarios will NOT trigger a StackOverflowError?
What happens when System.exit() is called inside try block?
Which exception is the parent class of all checked exceptions in Java (excluding RuntimeException)?
Consider a scenario where multiple catch blocks are written. What is the correct order? I. catch(FileNotFoundException e) II. catch(IOException e) III. catch(Exception e)
What will this code output? int result = 0; try { result = ; } catch(Exception e) { result = 20; return result; } finally { result = 30; } System.out.println(result);
Which of the following custom exceptions would be inappropriate to extend from RuntimeException in a banking application?
In exception chaining, what is the primary benefit?
If a finally block contains a return statement, what happens to an exception thrown in the try block?
In Java 7+, exception handling introduced 'multi-catch' feature using the pipe (|) operator. What's a limitation of multi-catch blocks?
Which scenario would cause a StackOverflowError in Java exception handling?