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.

51.

There can be a try block without catch block but vice versa is not possible.(a) True(b) FalseThe question was asked in examination.My question comes from Exception Handling in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct choice is (a) True

For EXPLANATION: The try block MAY or may not have any catch block. But a catch block can’t be there in a PROGRAM if there is no try block. It is LIKE else-block can only be written if and only if if-block is PRESENT in the program.

52.

Which are the two blocks that are used to check error and handle the error?(a) Try and catch(b) Trying and catching(c) Do and while(d) TryDo and CheckThe question was asked in a national level competition.This interesting question is from Exception Handling topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (a) Try and catch

To explain: TWO blocks that are used to CHECK for errors and to handle the errors are try and catch block. The code which might produce some EXCEPTIONS is placed INSIDE the try block and then the catch block is written to catch the error that is produced. The error message or any other processing can be done in catch block if the error is produced.
53.

What are two exception classes in hierarchy of java exceptions class?(a) Runtime exceptions only(b) Compile time exceptions only(c) Runtime exceptions and other exceptions(d) Other exceptionsThe question was posed to me in an online quiz.This intriguing question originated from Exception Handling topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Correct option is (c) RUNTIME EXCEPTIONS and other exceptions

Best explanation: The exceptions class is having two other derived classes which are of runtime exception handler and for other type of exceptions handling. The runtime exception handler is USED to handle the exceptions PRODUCED during run time and same with case of other exceptions.

54.

Which is the universal exception handler class?(a) Object(b) Math(c) Errors(d) ExceptionsThis question was addressed to me in an online quiz.I would like to ask this question from Exception Handling in division Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right CHOICE is (d) Exceptions

The best I can EXPLAIN: Any type of exception can be handled by using class Exceptions. An object of this class is created which can manipulate the exception data. The data can be USED to display the error or to run the program further BASED on error produced.

55.

If a file that needs to be opened is not found in the target location then _____________(a) Exception will be produced(b) Exceptions are not produced(c) Exception might get produced because of syntax(d) Exceptions are not produced because of logicI got this question during an interview.My question is from Exception Handling topic in section Exception Handling & Static Class Members of Object Oriented Programming

Answer» CORRECT choice is (a) Exception will be PRODUCED

To explain: The exceptions are produced when anything unexpected happened. The program might not be ABLE to find a FILE in the target LOCATION and hence program produces an exceptions. The exception produced, then terminates the program.
56.

An exception may arise when _______________(a) Input is fixed(b) Input is some constant value of program(c) Input given is invalid(d) Input is validI got this question in semester exam.My query is from Exception Handling topic in division Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (C) Input given is INVALID

Explanation: The exceptions may arise because the input given by the user might not be of the same type that a program can manage. If the input is invalid the program gets TERMINATED.
57.

Why do we need to handle exceptions?(a) To prevent abnormal termination of program(b) To encourage exception prone program(c) To avoid syntax errors(d) To save memoryI got this question in my homework.I'd like to ask this question from Exception Handling in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer» RIGHT answer is (a) To prevent abnormal TERMINATION of program

Explanation: The exceptions should be handled to prevent any abnormal termination of a program. The program should keep running even if it gets INTERRUPTED in between. The program should preferable show the ERROR occurred and then retry the PROCESS or just continue the program further.
58.

What is an exception?(a) Problem arising during compile time(b) Problem arising during runtime(c) Problem in syntax(d) Problem in IDEThis question was addressed to me during an interview.I need to ask this question from Exception Handling in chapter Exception Handling & Static Class Members of Object Oriented Programming

Answer»

Right answer is (b) PROBLEM arising during runtime

Explanation: The problems that might occur during execution of a program are known as exceptions. The exceptions are unexpected sometimes and can be PREDICTED. Also, the exceptions should be ALWAYS CONSIDERED for a better program.