I think it's time to get back to a bit more technical topics. Today I would like to talk about polymorphism recruitment questions. I my opinion, this is a very important element of any job interview as a C++ developer. We may have trouble answering other questions, but here in the case of polymorphism, we need to demonstrate a very good understanding of the subject. Typically, questions related to this topic are theoretical and practical in nature. Below are some questions I encountered:
I think these questions above are such classics. We will answer the first two today. I will devote a separate post to questions related to snippets, vptr, vtable and the diamond problem.
The first question was about the definition of polymorphism. I must admit that during my first recruitment interviews, it was difficult for me to answer this question. The more I understood object-oriented programming, the answer was more and more natural to me. I think with a clear conscience we can answer in this way and it will be the answer accepted by the recruiter:“IN CASE OF POLYMORPHISM, THE BASE CLASS TYPE POINTER MAY POINT TO AN OBJECT OF THE DERIVED CLASS”
The second question was to give an example of polymorphism on the example of class hierarchy. I was asked about this during a phone interview. My verbal answer was based on the following example:
I described in words what you can see, i.e. the base class "Animal" with one virtual method "animalSound". Two classes that inherit from it and create their own implementations of this method. It is also important to discuss the lines between 38 and 40 after the reassignment to the base class type pointer.
I think that would be enough for today. In the next post, I will present some snippets that you can come across at a job interview.