ProgrammingModerateProduct-company placement · C++

What is printed?

What is printed?
int main() {
    try { throw runtime_error("disk full"); }
    catch (const exception& e) { cout << e.what(); }
}
  1. A. std::exception
  2. B. disk full
  3. C. runtime_error
  4. D. Unknown exception

Correct answer: B. disk full

runtime_error derives from std::exception, so the handler matches, and the virtual what() returns the message passed to the constructor.

More OOP with C++ and Java questions

Exams that ask this topic