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.441Easy

What is the difference between 'throw' and 'throws' keywords in Java?

Q.442Medium

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

Q.443Medium

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.444Easy

Which exception is thrown when a method argument is null but shouldn't be?

Q.445Medium

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

Q.446Hard

Which of the following is NOT a characteristic of Exception class in Java?

Q.447Medium

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.448Hard

Which of the following cannot throw a checked exception without being declared in throws clause?

Q.449Medium

What is the output of exception chaining in Java?

Q.450Medium

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

Q.451Easy

What happens when an unchecked exception is not caught?

Q.452Easy

Which exception is thrown when attempting to access an index outside the bounds of an array?

Q.453Hard

What is the execution order in try-catch-finally for nested exception handling?

Q.454Easy

Consider a method signature: public void readFile() throws IOException. Which statement is correct?

Q.455Hard

What is suppressed exception in Java (introduced in Java 7)?

Q.456Easy

Which of the following statements about try-catch-finally blocks is correct?

Q.457Easy

What is the output of the following code? public class ExceptionTest { public static void main(String[] args) { try { int x = ; } catch (ArithmeticException e) { System.out.println("Caught"); } finally { System.out.println("Finally"); } } }

Q.458Easy

What will be the output? public class Test { public static void main(String[] args) { try { throw new Exception("Test"); } catch (Exception e) { System.out.println("1"); } catch (Exception e) { System.out.println("2"); } } }

Q.459Medium

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

Q.460Medium

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