Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
C
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
View Answer
B
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
View Answer
C
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A