Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of these methods return localized description of an exception?(a) getLocalizedMessage()(b) getMessage()(c) obtainLocalizedMessage()(d) printLocalizedMessage()The question was posed to me during a job interview.Query is from Creating Exceptions in section Exception Handling of Java

Answer»

The CORRECT ANSWER is (a) getLocalizedMessage()

The BEST EXPLANATION: NONE.

2.

Which of these methods is used to print stack trace?(a) obtainStackTrace()(b) printStackTrace()(c) getStackTrace()(d) displayStackTrace()I got this question in exam.This interesting question is from Creating Exceptions in section Exception Handling of Java

Answer»

The CORRECT OPTION is (B) printStackTrace()

The EXPLANATION: NONE.

3.

Which of these methods return description of an exception?(a) getException()(b) getMessage()(c) obtainDescription()(d) obtainException()I have been asked this question in a job interview.Asked question is from Creating Exceptions topic in portion Exception Handling of Java

Answer» CORRECT answer is (B) getMessage()

Easy explanation: getMessage() returns a description of the EXCEPTION.
4.

Which of these classes is used to define exceptions?(a) Exception(b) Throwable(c) Abstract(d) SystemThis question was addressed to me in an online interview.Question is from Creating Exceptions in portion Exception Handling of Java

Answer» RIGHT CHOICE is (a) Exception

For EXPLANATION: NONE.
5.

Which of these keywords are used for generating an exception manually?(a) try(b) catch(c) throw(d) checkI had been asked this question by my college professor while I was bunking the class.The above asked question is from Try & Catch in division Exception Handling of Java

Answer» RIGHT CHOICE is (C) throw

The EXPLANATION: NONE.
6.

Which of these keywords are used for the block to handle the exceptions generated by try block?(a) try(b) catch(c) throw(d) checkThe question was posed to me during an internship interview.My question comes from Try & Catch topic in division Exception Handling of Java

Answer» RIGHT ANSWER is (B) catch

Easiest EXPLANATION: NONE.
7.

Which of these keywords are used for the block to be examined for exceptions?(a) try(b) catch(c) throw(d) checkI got this question by my college director while I was bunking the class.This key question is from Try & Catch in division Exception Handling of Java

Answer»

Right CHOICE is (a) TRY

For EXPLANATION: try is used for the block that needs to checked for EXCEPTION.

8.

A single try block must be followed by which of these?(a) finally(b) catch(c) finally & catch(d) none of the mentionedThis question was addressed to me by my college director while I was bunking the class.The doubt is from Finally & Built in Exceptions topic in section Exception Handling of Java

Answer»

The correct OPTION is (c) finally & catch

To EXPLAIN I WOULD say: try block can be followed by any of finally or catch block, try block checks for exceptions and work is performed by finally and catch block as per the exception.

9.

Which of these exceptions handles the divide by zero error?(a) ArithmeticException(b) MathException(c) IllegalAccessException(d) IllegarExceptionI got this question in semester exam.The question is from Finally & Built in Exceptions in chapter Exception Handling of Java

Answer» RIGHT ANSWER is (a) ArithmeticException

The EXPLANATION is: NONE.
10.

What is the use of try & catch?(a) It allows us to manually handle the exception(b) It allows to fix errors(c) It prevents automatic terminating of the program in cases when an exception occurs(d) All of the mentionedThe question was asked in final exam.Asked question is from Try & Catch topic in section Exception Handling of Java

Answer» CORRECT ANSWER is (d) All of the mentioned

Best EXPLANATION: NONE.
11.

Which of these clause will be executed even if no exceptions are found?(a) throws(b) finally(c) throw(d) catchThe question was asked during an internship interview.Enquiry is from Finally & Built in Exceptions in division Exception Handling of Java

Answer»

Right choice is (b) finally

For explanation I WOULD say: finally keyword is USED to DEFINE a set of instructions that will be executed irrespective of the EXCEPTION found or not.

12.

Which of these operator is used to generate an instance of an exception than can be thrown by using throw?(a) new(b) malloc(c) alloc(d) thrownThe question was asked by my school principal while I was bunking the class.The question is from Throw, Throws & Nested Try in chapter Exception Handling of Java

Answer» RIGHT choice is (a) NEW

Easy explanation: new is USED to create an instance of an exception. All of java’s built in run-time exceptions have two constructors: one with no parameters and one that TAKES a STRING parameter.
13.

Which of these class is related to all the exceptions that can be caught by using catch?(a) Error(b) Exception(c) RuntimeExecption(d) All of the mentionedI had been asked this question in an interview.Query is from Exceptions Types in section Exception Handling of Java

Answer»

Right ANSWER is (b) EXCEPTION

For EXPLANATION: Error class is RELATED to java RUN time error that can’t be caught usually, RuntimeExecption is subclass of Exception class which contains all the exceptions that can be caught.

14.

Which of these class is related to all the exceptions that are explicitly thrown?(a) Error(b) Exception(c) Throwable(d) ThrowI had been asked this question in final exam.This intriguing question comes from Throw, Throws & Nested Try topic in section Exception Handling of Java

Answer» RIGHT OPTION is (C) Throwable

To ELABORATE: NONE.
15.

Which of these class is related to all the exceptions that cannot be caught?(a) Error(b) Exception(c) RuntimeExecption(d) All of the mentionedI got this question in exam.This interesting question is from Exceptions Types topic in chapter Exception Handling of Java

Answer»

The CORRECT option is (a) Error

Easiest explanation: Error class is RELATED to java run time error that can’t be CAUGHT USUALLY, RuntimeExecption is subclass of Exception class which contains all the exceptions that can be caught.

16.

Which of these keywords is used to generate an exception explicitly?(a) try(b) finally(c) throw(d) catchThis question was addressed to me during an interview for a job.Origin of the question is Throw, Throws & Nested Try topic in section Exception Handling of Java

Answer» CORRECT ANSWER is (C) throw

Best EXPLANATION: NONE.
17.

Which of these handles the exception when no catch is used?(a) Default handler(b) finally(c) throw handler(d) Java run time systemThe question was asked during an interview for a job.Query is from Exceptions Types topic in section Exception Handling of Java

Answer» RIGHT CHOICE is (a) DEFAULT handler

Explanation: NONE.
18.

Which of the following should be true of the object thrown by a thrown statement?(a) Should be assignable to String type(b) Should be assignable to Exception type(c) Should be assignable to Throwable type(d) Should be assignable to Error typeThis question was posed to me by my school teacher while I was bunking the class.This key question is from Exception Handling in portion Exception Handling of Java

Answer»

The CORRECT choice is (c) Should be ASSIGNABLE to THROWABLE type

The best I can explain: The throw STATEMENT should be assignable to the throwable type. Throwable is the super class of all exceptions.

19.

Which of these is a super class of all exceptional type classes?(a) String(b) RuntimeExceptions(c) Throwable(d) CacheableI have been asked this question in an internship interview.Query is from Exceptions Types topic in section Exception Handling of Java

Answer»

The CORRECT choice is (C) Throwable

Easiest EXPLANATION: All the exception TYPES are subclasses of the BUILT in class Throwable.

20.

At runtime, error is recoverable.(a) True(b) FalseI have been asked this question by my college professor while I was bunking the class.I'd like to ask this question from Exception Handling topic in chapter Exception Handling of Java

Answer»

Correct option is (b) False

To explain I WOULD SAY: ERROR is not RECOVERABLE at runtime. The control is lost from the APPLICATION.

21.

Which part of code gets executed whether exception is caught or not?(a) finally(b) try(c) catch(d) throwThis question was addressed to me in a national level competition.I want to ask this question from Exception Handling topic in chapter Exception Handling of Java

Answer»

The correct option is (a) FINALLY

The EXPLANATION is: Finally block of the code gets executed regardless EXCEPTION is caught or not. File close, database connection close, ETC are usually DONE in finally.

22.

Which of the following handles the exception when a catch is not used?(a) finally(b) throw handler(c) default handler(d) java run time systemI got this question by my school principal while I was bunking the class.Question is taken from Exception Handling in portion Exception Handling of Java

Answer»

Right option is (C) default handler

Easiest explanation: Default handler is used to HANDLE all the exceptions if catch is not used to handle exception. FINALLY is called in any case.

23.

Which of the following operators is used to generate instance of an exception which can be thrown using throw?(a) thrown(b) alloc(c) malloc(d) newThe question was asked during an online interview.This intriguing question originated from Exception Handling in section Exception Handling of Java

Answer» RIGHT CHOICE is (d) new

For explanation I would say: new OPERATOR is used to CREATE instance of an exception. Exceptions may have parameter as a String or have no parameter.
24.

Which of the following keyword is used by calling function to handle exception thrown by called function?(a) throws(b) throw(c) try(d) catchThis question was posed to me during an interview for a job.Question is from Exception Handling in section Exception Handling of Java

Answer» CORRECT answer is (a) throws

To explain I would say: A method specifies behaviour of being capable of causing exception. Throws clause in the method DECLARATION GUARDS caller of the method from exception.
25.

Which of the following is a super class of all exception type classes?(a) Catchable(b) RuntimeExceptions(c) String(d) ThrowableThe question was asked in class test.I want to ask this question from Exception Handling topic in section Exception Handling of Java

Answer»

Correct ANSWER is (d) THROWABLE

For EXPLANATION: Throwable is BUILT in CLASS and all exception types are subclass of this class. It is the super class of all exceptions.

26.

Which of the following classes can catch all exceptions which cannot be caught?(a) RuntimeException(b) Error(c) Exception(d) ParentExceptionI got this question in a national level competition.My question is from Exception Handling in portion Exception Handling of Java

Answer»

Correct CHOICE is (b) Error

To ELABORATE: Runtime errors cannot be CAUGHT GENERALLY. Error CLASS is used to catch such errors/exceptions.

27.

Which of the following keywords is used for throwing exception manually?(a) finally(b) try(c) throw(d) catchI had been asked this question by my school principal while I was bunking the class.I'd like to ask this question from Exception Handling topic in chapter Exception Handling of Java

Answer» RIGHT choice is (c) throw

Easy explanation: “throw’ KEYWORD is used for throwing exception manually in JAVA PROGRAM. User defined exceptions can be thrown too.
28.

Which of these keywords must be used to monitor for exceptions?(a) try(b) finally(c) throw(d) catchI have been asked this question by my school teacher while I was bunking the class.My query is from Exceptional Handling Basics in section Exception Handling of Java

Answer»

The CORRECT OPTION is (a) try

Easiest EXPLANATION: NONE.

29.

Which of these keywords must be used to handle the exception thrown by try block in some rational manner?(a) try(b) finally(c) throw(d) catchThis question was posed to me by my school teacher while I was bunking the class.Enquiry is from Exceptional Handling Basics topic in section Exception Handling of Java

Answer» RIGHT answer is (d) catch

Explanation: If an exception OCCURS within the try BLOCK, it is thrown and CACHED by catch block for processing.
30.

Which of these keywords is not a part of exception handling?(a) try(b) finally(c) thrown(d) catchI got this question in an interview for internship.Enquiry is from Exceptional Handling Basics topic in division Exception Handling of Java

Answer»

Correct answer is (c) thrown

Best explanation: Exceptional handling is managed via 5 KEYWORDSTRY, CATCH, THROWS, throw and finally.

31.

When does Exceptions in Java arises in code sequence?(a) Run Time(b) Compilation Time(c) Can Occur Any Time(d) None of the mentionedThis question was posed to me during an interview for a job.This interesting question is from Exceptional Handling Basics in chapter Exception Handling of Java

Answer»

The correct choice is (a) Run Time

To EXPLAIN I would SAY: Exceptions in JAVA are run-time errors.