ProgrammingVery hardProduct-company placement · C++
How many of these statements about C++ are correct? (i) A constructor cannot be declared virtual. (ii) A static member function cannot be virtual. (iii) A virtual function declared private in the base class can still be overridden in a derived class. (iv) A destructor cannot be declared pure virtual.
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: B. 3
(i), (ii) and (iii) are correct (access control does not affect overriding; this is the NVI idiom). (iv) is false: a pure virtual destructor is allowed and makes the class abstract, but it must still be given a definition.
More OOP with C++ and Java questions
- What is printed? cpp template <class T> void f(T) { cout << "1"; } template <> void f(int) { cout << "2"; } // explicit specialisation…
- What is printed? cpp template <int N> struct F { static const int v = N F<N - 1>::v; }; template <> struct F<0> { static const int v = 1…
- What is printed? cpp struct M { M() { throw 1; } }; struct S { M m; S() try : m() { } catch (int) { cout << "S"; } }; int main() { try { S…
- What is printed? cpp void f() noexcept { } void g() { } int main() { cout << noexcept(f()) << noexcept(g()); }
- What happens when this is compiled? cpp int main() { try { throw 1; } catch (...) { cout << "any"; } catch (int) { cout << "int"; } }
- What is printed? cpp int main() { try { throw runtimeerror("disk full"); } catch (const exception& e) { cout << e.what(); } }