Java Exception Handling MCQ – 1

Q1) Which class acts as the root for all Java exception Hierarchy?

a) Exception class
b) Throwable class
c) Error class
d) None of these

View Answer Answer:- b) Throwable class

Q2) Which option is true?

a) Throwable is an interface.
b) Throwable is an abstract class.
c) Throwable is a class.
d) Throwable is an Enum.

View Answer Answer:- c) Throwable is a class.

Q3) Throwable class contains how many child classes?

a) 2
b) 0
c) 1
d) 3

View Answer Answer:- a) 2

Throwable class contains 2 child classes:- Exception and Error.

Q4) We get checked exceptions at (Or, checked exception raises at)?

a) Compile time
b) Runtime
c) Both (a) and (b)
d) None of these

View Answer Answer:- b) Runtime

Whether it is a checked exception or unchecked exception, all exceptions are raised at runtime only.

Q5) Which exception will raise in the below statement?

System.out.println(9/0);

a) NumberFormatException
b) RuntimeException
c) ArithmeticException
d) None of these

View Answer Answer:- c) ArithmeticException

java.lang.ArithmeticException: / by zero

Q6) Which exception will raise in the below statement?

int n1 = Integer.parseInt("ten");

a) NumberFormatException
b) NullPointerException
c) ArithmeticException
d) None of these

View Answer Answer:- a) NumberFormatException

java.lang.NumberFormatException: For input string: “ten”

Q7) Which exception will raise in the below statement?

String s = null;
System.out.println(s.length());

a) NumberFormatException
b) NullPointerException
c) ArithmeticException
d) None of these

View Answer Answer:- b) NullPointerException

java.lang.NullPointerException: Cannot invoke “String.length()” because “s” is null.

Q8) RuntimeException class is a subclass of?

a) Error
b) Exception
c) ArithmeticException
d) None of these

View Answer Answer:- b) Exception

Q9) Which keyword is not used in exception handling?

a) throw
b) throws
c) thrown
d) All of these

View Answer Answer:- c) thrown

Java doesn’t contain the “thrown” keyword.

Q10) How many keywords are given to work with exceptions?

a) 5
b) 4
c) 3
d) 9

View Answer Answer:- a) 5

In Java 5 keywords are given specially to work with exception. They are:- try, catch, finally, throw and throws.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

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