Test Series - oops

Test Number 60/78

Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: Which among the following handles the undefined class in program?
A. ClassNotFound
B. NoClassException
C. ClassFoundException
D. ClassNotFoundException
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: Since which version of java is multiple exception catch was made possible?
A. Java 4
B. Java 5
C. Java 6
D. Java 7
Solution: 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.
Q: How many catch blocks can a class have?
A. Only 1
B. 2
C. 3
D. As many as required
Solution: 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.

You Have Score    /10