Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 44
Q661:
What is the concept of stack unwinding in exception handling?
A. Order of function calls
B. Destruction of local variables
C. Cleanup of dynamically allocated memory
D. Handling exceptions in catch blocks
Correct Answer:
B
Chapter: 44
Q662:
What happens to local variables in a try block when an exception is thrown?
A. They are kept unchanged
B. They are destroyed
C. They are modified
D. They are ignored
Correct Answer:
B
Chapter: 44
Q663:
When an exception is thrown from nested functions, what is the sequence of control transfer called?
A. Stack unwinding
B. Exception handling
C. Error propagation
D. Function return
Correct Answer:
A
Chapter: 44
Q664:
In stack unwinding, what is the order of handling exceptions in nested try-catch blocks?
A. Innermost try-catch first
B. Outermost try-catch first
C. Random order
D. All try-catch blocks simultaneously
Correct Answer:
A
Chapter: 44
Q665:
How does C++ handle exceptions if no catch handler is found?
A. It terminates the program
B. It ignores the exception
C. It retries the code
D. It skips the catch blocks
Correct Answer:
A
Chapter: 44
Q666:
What is the purpose of the throw keyword in exception handling?
A. To catch an exception
B. To throw an exception
C. To end the program
D. To return a value
Correct Answer:
B
Chapter: 44
Q667:
What happens to dynamically allocated memory when an exception is thrown?
A. It is automatically freed
B. It remains allocated
C. It is partially freed
D. It causes a memory leak
Correct Answer:
B
Chapter: 44
Q668:
What will happen if a catch block does not match the thrown exception type?
A. The program crashes
B. The catch block is skipped
C. The catch block handles the exception
D. The program continues without handling
Correct Answer:
B
Chapter: 44
Q669:
What is the role of the catch block when an exception is thrown?
A. To throw another exception
B. To handle the thrown exception
C. To terminate the program
D. To log the error
Correct Answer:
B
Chapter: 44
Q670:
In the provided example, which class represents the exception for division by zero?
A. DivideByZero
B. Exception
C. Error
D. ZeroDivision
Correct Answer:
A
Chapter: 45
Q671:
What is the issue with the function function1 when an exception is thrown without proper handling?
A. File is closed properly
B. Resource wastage due to unopened file
C. File remains open and is not closed
D. File pointer is reset
Correct Answer:
C
Chapter: 45
Q672:
How can resource wastage be avoided when throwing exceptions in function1?
A. Using code duplication
B. Adding fclose in the catch block
C. Using global variables
D. Ignoring exceptions
Correct Answer:
B
Chapter: 45
Q673:
What is the purpose of the FilePtr class in the second attempt to manage file resources?
A. To keep the file open manually
B. To handle file operations in a more secure way
C. To automatically close the file when object is destroyed
D. To handle file exceptions manually
Correct Answer:
C
Chapter: 45
Q674:
What happens when an exception is thrown in a constructor in terms of object destruction?
A. All objects created so far are destroyed
B. Only the object that threw the exception is destroyed
C. Only the partially constructed object is destroyed
D. No objects are destroyed
Correct Answer:
A
Chapter: 45
Q675:
If an exception occurs in the initialization list of a constructor, where can it be caught?
A. In the member initialization list
B. In the destructor
C. In the catch block of the constructor
D. In the main function
Correct Answer:
A
Chapter: 45
Q676:
What should not be done in a destructor to avoid issues during stack unwinding?
A. Throw an exception
B. Return from the destructor
C. Catch exceptions in the destructor
D. Call another destructor
Correct Answer:
A
Chapter: 45
Q677:
What happens if an exception leaves the destructor during stack unwinding?
A. The program terminates abnormally
B. The exception is handled by another handler
C. The stack unwinding is paused
D. The destructor is ignored
Correct Answer:
A
Chapter: 45
Q678:
What does the throw() specification do in a function declaration?
A. Specifies the function cannot throw any exceptions
B. Specifies the function can throw all exceptions
C. Specifies the function can throw specific exceptions
D. Specifies the function can throw any exception of type Exception1 or derived classes
Correct Answer:
A
Chapter: 45
Q679:
What happens if a function throws an exception not listed in its throw() specification?
A. The function unexpected is called
B. The function terminates normally
C. The function handles the exception itself
D. The program ignores the exception
Correct Answer:
A