iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.21Easy

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

Which method is used to print the stack trace of an exception?

Q.23Easy

Which of the following is NOT a subclass of Throwable?

Q.24Easy

In Java exception handling, which of the following statements is true about the finally block?

Q.25Easy

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

Q.26Easy

Which exception is thrown when accessing an array element with an invalid index?

Q.27Easy

What is the correct syntax for declaring a method that throws a checked exception?

Q.28Easy

What will happen when the following code is executed?
try {
int[] arr = {1, 2, 3};
System.out.println(arr[5]);
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Exception caught");
}

Q.29Easy

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

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