📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    The following C++ code intends to demonstrate runtime

    polymorphism, but it's not working as expected. What is the issue? #include class Animal { public:     void makeSound() { // Problematic         std::cout
    A The `makeSound()` method in `Animal` is not declared `virtual`. Correct Answer Incorrect Answer
    B The `makeSound()` method in `Dog` is not declared `override`. Correct Answer Incorrect Answer
    C `Dog` should not inherit from `Animal`. Correct Answer Incorrect Answer
    D The `main` function should create a `Dog` object directly, not an `Animal` pointer. Correct Answer Incorrect Answer
    E There is no issue; the code works as intended. Correct Answer Incorrect Answer

    Solution

    The correct answer is A

    Practice Next
    ask-question