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

Which of the following will NOT result in a NullPointerException?

Q.482Medium

In Java, which method of Throwable class is used to obtain the cause of an exception?

Q.483Medium

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

Q.484Medium

Which of the following is true about try-with-resources (Java 7+)?

Q.485Medium

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

Q.486Hard

Which exception is the parent class of all checked exceptions in Java (excluding RuntimeException)?

Q.487Hard

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)

Q.488Hard

What will this code output? int result = 0; try { result = ; } catch(Exception e) { result = 20; return result; } finally { result = 30; } System.out.println(result);

Q.489Hard

Which of the following custom exceptions would be inappropriate to extend from RuntimeException in a banking application?

Q.490Hard

In exception chaining, what is the primary benefit?

Q.491Medium

In Java 8+, when using try-with-resources with multiple AutoCloseable resources, in what order are they closed?

Q.492Medium

Which of the following exceptions would NOT be caught by catching Exception class in Java?

Q.493Easy

What is the output of the following code? try { int x = ; } catch(ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); } System.out.println("After");

Q.494Hard

If a finally block contains a return statement, what happens to an exception thrown in the try block?

Q.495Medium

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?

Q.496Easy

What is the primary difference between throw and throws in Java exception handling?

Q.497Hard

In Java 7+, exception handling introduced 'multi-catch' feature using the pipe (|) operator. What's a limitation of multi-catch blocks?

Q.498Medium

What does the getSuppressed() method of Throwable class return in context of try-with-resources?

Q.499Hard

Which scenario would cause a StackOverflowError in Java exception handling?

Q.500Medium

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?