-
Question on polymorphism
I know that to truly partake in polymorphism a class must have at least one virtual method. My question is, what if a class "A" inherits from a base class "B" that has a virtual method, does "A" also need a virtual method for it to be able to be inherited (and partake in polymorphism) properly or does the virtual method from the base class cover that?
-
No, once a method is declared as virtual, it stays virtual in all child classes, whether the derived classes specify it as virtual or not.
But I usually specify virtual all the way down the chain just for consistency and to remind you that it is virtual without having to look at all the base classes to find out.
-
The inherited method (i.e., virtual member function) is also A's method, even if the virtual keyword is not used when defining A.
-
Before you go whole hog with inheritance and polymorphism, I'd recommend reading this article.
Liskov Substitution Principle