MCQ

Java MCQ – Exception Handling – Part 2

This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Exception Handling in Java”.
 

1. Which of these classes is a super class of all Exception classes?

A RuntimeExceptions

B String

C Throwable

D Cachable

C
Throwable class is a super class of all Exception classes.


 

 

2. Which of these classes is related to all the exceptions that can be caught using catch?

A Error

B Exception

C RuntimeExecption

D All the answers are true

B
The Error class is associated with a runtime error which generally cannot be caught, RuntimeExecption is a subclass of the Exception class which contains all the exceptions that can be caught.

 

 

3. Which of these classes is related to all the exceptions that cannot be caught?

A Error

B Exception

C RuntimeExecption

D All the answers are true

A
The Error class is associated with a runtime error which generally cannot be caught, RuntimeExecption is a subclass of the Exception class which contains all the exceptions that can be caught.

 

 

4. Which of these operators is used to generate an instance of an exception which can be thrown using throw?

A new

B malloc

C throws

D thrown

A
new is used to create the instance of an exception. All built-in runtime exceptions have two constructors: one without parameters and one that takes a parameter of type String. Example:

if(age < 18)  
    throw new ArithmeticException("not valid");

 

 

5. What is the output of the following code?
public class Main 
{
	public static void main(String args[]) 
	{
		try 
		{
			int a = 5 / 0;
			System.out.print("TRY");
		}
		catch(ArithmeticException e) 
		{
			System.out.print("CATCH");        	
		}
	}
}

A TRY

B CATCH

C TRYCATCH

D CATCHTRY

B

 

 

6. Which block is always executed, regardless of the exception thrown?

A throws

B finally

C catch

D throw

B
The finally block always executes at the end of the try block. This ensures that the finally block is executed even if an unexpected exception occurs.

 

 

7. Exception and Error are direct subclasses of _____

A Throwable

B BaseException

C RuntimeException

D Object

A


 

 

8. FileNotFoundException

A Inherits from the IOException class

B Is an exception at compile time

C Found in the java.io package

D All the answers are true

D

 

 

9. IOException

A Is a subclass of Exception

B Is an exception at compile time

C Found in the java.io package

D All the answers are true

D

 

 

10. The multiple catch syntax was introduced in _____

A java 5

B java 6

C java 7

D java 8

C

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *