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

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

Q.42Medium

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

Q.43Medium

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

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

Q.45Medium

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

Q.46Hard

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

Q.47Medium

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

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

Q.49Medium

What is the output of exception chaining in Java?

Q.50Medium

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

Q.51Easy

What happens when an unchecked exception is not caught?

Q.52Easy

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

Q.53Hard

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

Q.54Easy

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

Q.55Hard

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

Q.56Easy

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

Q.57Easy

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

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

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

Q.60Medium

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