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
What is the difference between 'throw' and 'throws' keywords in Java?
Consider this code snippet. What will happen? try { int x = ; } catch (NullPointerException e) { System.out.println("Caught NPE"); }
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"); } } }
Which exception is thrown when a method argument is null but shouldn't be?
What happens if you use 'return' statement inside a finally block?
Which of the following is NOT a characteristic of Exception class in Java?
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"); } } }
Which of the following cannot throw a checked exception without being declared in throws clause?
What is the output of exception chaining in Java?
Which method is used to get the exception that caused the current exception in Java?
What happens when an unchecked exception is not caught?
Which exception is thrown when attempting to access an index outside the bounds of an array?
What is the execution order in try-catch-finally for nested exception handling?
Consider a method signature: public void readFile() throws IOException. Which statement is correct?
What is suppressed exception in Java (introduced in Java 7)?
Which of the following statements about try-catch-finally blocks is correct?
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"); } } }
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"); } } }
Which exception is thrown when a thread tries to acquire a monitor that is already locked?
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()); } }