250+ TOP MCQs on Catching Class Types and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Catching Class Types”.

1. Which among the following is true for class exceptions?
a) Only base class can give rise to exceptions
b) Only derived class can give rise to exceptions
c) Either base class or derived class may produce exceptions
d) Both base class and derived class may produce exceptions
Answer: d
Clarification: It’s not mandatory that either base class or derived class can give rise to exceptions. The exceptions might get produced from any class. The exceptions depends on code.

2. If both base and derived class caught exceptions ______________
a) Then catch block of derived class must be defined before base class
b) Then catch block of base class must be defined before the derived class
c) Then catch block of base and derived classes doesn’t matter
d) Then catch block of base and derived classes are not mandatory to be defined
Answer: a
Clarification: It is a condition for writing the catch blocks for base and derived classes. It is mandatory to write derived class catch block first because the errors produced by the derived class must be handled first.

3. Which among the following is true?
a) If catch block of base class is written first, it is compile time error
b) If catch block of base class is written first, it is run time error
c) If catch block of base class is written first, derived class catch block can’t be reached
d) If catch block of base class is written first, only derived class catch block is executed
Answer: c
Clarification: If the catch block of the base class is defined first and then the derived class catch block is given. The code becomes unreachable. Hence the derived class catch block must be written first.

4. The catching of base class exception ___________________________ in java.
a) After derived class is not allowed by compiler
b) Before derived class is not allowed by compiler
c) Before derived class is allowed
d) After derived class can’t be done
Answer: b
Clarification: The catching of base class exception before derived class is not allowed in java. The compiler itself doesn’t allow this declaration. It produces an error.

5. If catching of base class exception is done before derived class in C++ ________________
a) It gives compile time error
b) It doesn’t run the program
c) It may give warning but not error
d) It always gives compile time error
Answer: c
Clarification: The compiler in C++ doesn’t identify this as compile time error and allows the execution of the program. But, the compiler may give some warning related to the catch block sequence or code unreachable.

6. How many catch blocks can a class have?
a) Only 1
b) 2
c) 3
d) As many as required
Answer: d
Clarification: There are many type of exceptions that may arise while running a code. And each catch block can handle only one exception. Hence there can be as many catch blocks as required.

7. Since which version of java is multiple exception catch was made possible?
a) Java 4
b) Java 5
c) Java 6
d) Java 7
Answer: d
Clarification: None of the languages used to support multiple exception catch in a single catch block. Since java 7 the feature was added to catch more than one exceptions in one catch block.

8. To catch more than one exception in one catch block, how are the exceptions separated in the syntax?
a) Vertical bar
b) Hyphen
c) Plus
d) Modulus
Answer: a
Clarification: Just the way we separate the arguments in a function definition using comma. Here we separate the exceptions by using a vertical bar or we call it pipe symbol sometimes. This is just a convention followed to separate different exception list.

9. If a catch block accepts more than one exceptions then __________________
a) The catch parameters are not final
b) The catch parameters are final
c) The catch parameters are not defined
d) The catch parameters are not used
Answer: b
Clarification: The catch parameters are made final. This is to ensure that the parameters are not changed inside the catch block. Hence those retain their values.

10. Which among the following handles the undefined class in program?
a) ClassNotFound
b) NoClassException
c) ClassFoundException
d) ClassNotFoundException
Answer: d
Clarification: It is the exception handler that handles the exceptions when the class used is not found in the program. This is done to handle all the undefined class exceptions. This can be due to a command line error.

11. If classes produce some exceptions, then ______________________
a) Their respective catch block must be defined
b) Their respective catch blocks are not mandatory
c) Their catch blocks should be defined inside main function
d) Their catch blocks must be defined at the end of program
Answer: a
Clarification: The catch blocks must be defined. This is to ensure that all the exceptions related to the classes are handled by the program code and the program doesn’t terminate unexpectedly.

12. Which among the following is true?
a) Only the base class catch blocks are important
b) Only the derived class catch blocks are important
c) Both the base and derived class catch blocks are important
d) If base and derived classes both produce exceptions, program doesn’t run
Answer: c
Clarification: The purpose of exception handling is to handle the unexpected errors in the program. If base class might produce some error then its catch block must be given and if the derived class might produce some error then it must be given a specific catch block too.

13. Which is the necessary condition to define the base and derived class catch blocks?
a) Base class catch should be defined first
b) Derived class catch should be defined first
c) Catch block for both the classes must not be defined
d) Catch block must be defined inside main function
Answer: b
Clarification: The derived class catch blocks must be defined prior to the base class catch block. This is to ensure that all the catch boxes are reachable. If not done, the code might become unreachable which in turn makes the program prone to errors.

14. Only the base class catch box can handle more than one exception in single block.
a) True
b) False
Answer: b
Clarification: There is no specific condition that states that only base class catch box can handle more than one exception in single box. Even the derived class catch clocks can handle more than one exceptions.

15. Which condition among the following might result in memory exception?
a) False if conditions
b) Nested if conditions that are all false
c) Infinite loops
d) Loop that runs exactly 99 times
Answer: c
Clarification: The infinite loops doesn’t stop running once started. There must be a way to stop the loop but that is always an improper termination. Infinite loops may keep on using more memory and hence would result in memory error.

Leave a Reply

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