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

Analyze the code:
try {
return 5;
} finally {
return 10;
}
What will be returned?

Q.2Hard

What happens if an exception is thrown in the finally block?

Q.3Hard

Analyze the nested try-catch:
try {
try {
int x = ;
} catch(NullPointerException e) {
System.out.println("Inner");
}
} catch(ArithmeticException e) {
System.out.println("Outer");
}

Q.4Hard

What will be printed?
public class ExceptionTest {
public static void main(String[] args) {
try {
testMethod();
} catch (Exception e) {
System.out.println("Caught");
}
}

public static void testMethod() {
try {
throw new RuntimeException("Error");
} finally {
System.out.println("Finally");
}
}
}

Q.5Hard

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

Q.6Hard

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

Q.7Hard

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

Q.8Hard

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

Q.9Hard

What will be printed for this code?
public class ExceptionOrder {
public static void main(String[] args) {
try {
try {
throw new RuntimeException("Inner");
} catch (Exception e) {
throw new IOException("Outer");
}
} catch (IOException e) {
System.out.println("Caught IOException");
} catch (RuntimeException e) {
System.out.println("Caught RuntimeException");
}
}
}

Q.10Hard

Which of the following scenarios will NOT trigger a StackOverflowError?

Q.11Hard

What happens when System.exit() is called inside try block?

Q.12Hard

Which exception is the parent class of all checked exceptions in Java (excluding RuntimeException)?

Q.13Hard

Consider a scenario where multiple catch blocks are written. What is the correct order?
I. catch(FileNotFoundException e)
II. catch(IOException e)
III. catch(Exception e)

Q.14Hard

What will this code output?
int result = 0;
try {
result = ;
} catch(Exception e) {
result = 20;
return result;
} finally {
result = 30;
}
System.out.println(result);

Q.15Hard

Which of the following custom exceptions would be inappropriate to extend from RuntimeException in a banking application?

Q.16Hard

In exception chaining, what is the primary benefit?

Q.17Hard

If a finally block contains a return statement, what happens to an exception thrown in the try block?

Q.18Hard

In Java 7+, exception handling introduced 'multi-catch' feature using the pipe (|) operator. What's a limitation of multi-catch blocks?

Q.19Hard

Which scenario would cause a StackOverflowError in Java exception handling?