πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      In C++, to achieve runtime polymorphism, a base class

      method must be declared with which keyword?
      A static Correct Answer Incorrect Answer
      B final Correct Answer Incorrect Answer
      C abstract Correct Answer Incorrect Answer
      D virtual Correct Answer Incorrect Answer
      E override Correct Answer Incorrect Answer

      Solution

      In C++, for a method to be overridden polymorphically (i.e., for dynamic dispatch to occur), the base class method must be declared as virtual. If it's not virtual, the method call will be resolved at compile time based on the pointer/reference type, not the actual object type.

      Practice Next
      ask-question