ProgrammingHardProduct-company placement · C++

Which lines fail to compile?

Which lines fail to compile?
struct B { virtual void f() final { } virtual void g() { } };
struct D : B {
    void f() { }           // L1
    void g() final { }     // L2
};
struct E final : D { };    // L3
struct F : E { };          // L4
  1. A. L1 only
  2. B. L1 and L4
  3. C. L1, L2 and L4
  4. D. L4 only

Correct answer: B. L1 and L4

A final virtual function cannot be overridden (L1) and a final class cannot be derived from (L4). Marking an override as final (L2) and declaring a final class (L3) are fine.

More OOP with C++ and Java questions

Exams that ask this topic