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 << "Animal sound" << std::endl;     } }; class Dog : public Animal { public:     void makeSound() {         std::cout << "Woof" << std::endl;     } }; int main() {     Animal* a = new Dog();     a->makeSound(); // Calls Animal's makeSound     delete a;     return 0; }

A The `makeSound()` method in `Animal` is not declared `virtual`.
B The `makeSound()` method in `Dog` is not declared `override`.
C `Dog` should not inherit from `Animal`.
D The `main` function should create a `Dog` object directly, not an `Animal` pointer.
E There is no issue; the code works as intended.
Practice Next

Hey! Ask a query

🎓
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
  • 200 Questions with Detailed Solutions
  • Section-wise Coverage (GA, English, Quant & Reasoning)