With polymorphism you can have it set up like that, you have to hold the pointer to the objects. if you need to use functionality which is present higher in the inheritance of the true object then you have to use a dynamic_cast
the program returns 10
as an extension of this you can store the pointers in a vector instead.
You can learn more here