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

What is the output of the following code? int x = 10; try { x = x / 0; } catch(ArithmeticException e) { x = x + 5; } finally { x = x * 2; } System.out.println(x);

Q.2Medium

What will be the output? try { throw new Exception("Test"); } catch(Exception e) { System.out.println("Caught"); } finally { System.out.println("Finally"); }

Q.3Medium

What is the output of multiple catch blocks? try { int[] arr = {1, 2, 3}; System.out.println(arr[5]); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Index"); } catch(Exception e) { System.out.println("Exception"); }

Q.4Medium

Which of the following exceptions is a checked exception?

Q.5Medium

Which statement about try-with-resources is TRUE?

Q.6Medium

What is the output? try { int x = ; } catch(Exception e) { System.out.println("Caught"); } catch(ArithmeticException ae) { System.out.println("Arithmetic"); }

Q.7Medium

Analyze this code: public void test() throws IOException { // method body } What does 'throws' indicate?

Q.8Medium

Which exception hierarchy is correct in Java?

Q.9Medium

What will happen if you don't catch a checked exception?

Q.10Medium

Which statement about multiple catch blocks is TRUE?

Q.11Medium

Analyze the code: public void process() throws IOException { try { readFile(); } catch (FileNotFoundException e) { // handle } } What is the issue here?

Q.12Medium

What happens if you throw an exception inside the finally block?

Q.13Medium

Consider the code: try (FileReader fr = new FileReader("file.txt")) { // use fr } catch (IOException e) { // handle } What will happen to 'fr' after the try block?

Q.14Medium

Which of these is NOT a correct way to handle checked exceptions?

Q.15Medium

What is the output? public class Test { public static void main(String[] args) { int x = 0; try { x = 5; System.out.println(x / 0); x = 10; } catch (ArithmeticException e) { x = 15; } finally { System.out.println(x); } } }

Q.16Medium

What will happen if a finally block contains a return statement?

Q.17Medium

Analyze the code: try { // code } catch (IOException | SQLException e) { // handle } What is this syntax called?

Q.18Medium

What is the difference between throw and throws?

Q.19Medium

Consider this code: public static void main(String[] args) { try { System.out.println("A"); return; } finally { System.out.println("B"); } } What is the output?

Q.20Medium

Which of the following cannot be used with try-with-resources?