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

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

Q.202Medium

Which exception hierarchy is correct in Java?

Q.203Medium

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

Q.204Medium

Which statement about multiple catch blocks is TRUE?

Q.205Medium

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

Q.206Medium

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

Q.207Medium

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

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

Q.209Medium

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

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

Q.211Medium

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

Q.212Medium

What is the difference between throw and throws?

Q.213Medium

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

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

Q.215Medium

Which statement is TRUE about exception propagation in Java?

Q.216Medium

What will be the behavior if an exception is thrown in the finally block?

Q.217Medium

Which statement about try-with-resources (introduced in Java 7) is correct?

Q.218Medium

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

Q.219Medium

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

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