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
Consider the following exception hierarchy. Which statement will compile without error? class MyException extends Exception {} class MyRuntimeException extends RuntimeException {}
Which of the following will NOT result in a NullPointerException?
In Java, which method of Throwable class is used to obtain the cause of an exception?
What will be printed when this code executes? String str = "Java"; try { int x = Integer.parseInt(str); } catch(NumberFormatException e) { System.out.println("Invalid number"); } catch(Exception e) { System.out.println("General exception"); }
Which of the following is true about try-with-resources (Java 7+)?
What will be the output of this code? try { try { throw new Exception("Inner"); } catch(Exception e) { throw new RuntimeException("Outer"); } } catch(RuntimeException e) { System.out.println("Caught: " + e.getMessage()); }
In Java 8+, when using try-with-resources with multiple AutoCloseable resources, in what order are they closed?
Which of the following exceptions would NOT be caught by catching Exception class in Java?
Consider a scenario where you have nested try-catch blocks. If both inner and outer catch blocks match the thrown exception type, which one executes?
What does the getSuppressed() method of Throwable class return in context of try-with-resources?
In Java, when an exception is thrown in a try block and caught in a catch block, if the catch block also throws an exception, what happens to the original exception?