Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Token final {
public:
int id = 1;
};
class SpecialToken : public Token {};
int main() {
SpecialToken t;
std::cout << t.id << '\n';
return 0;
}
- A id must be private
- B Token is declared final, so no class may inherit from it Correct
- C SpecialToken needs a constructor
- D final can only be used on functions
Correct Answer: Option B
final on a class prevents derivation; on a virtual function it prevents further overriding.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!