Skip to content
Preptima

Top 5 Polymorphism Interview Questions

Browse 5 real-world technical and behavioral interview questions about Polymorphism. Review scenarios, edge cases, and architectural best practices.

Skip the definitions. Show me encapsulation, abstraction, inheritance and polymorphism, each in about ten lines of code, and then tell me when inheritance is the wrong tool.

OOP examples beat definitions: a class refusing a bad withdrawal shows encapsulation, a caller depending on an interface shows abstraction, a subclass reusing a parent method shows inheritance, and one loop running different overrides shows polymorphism. Inheritance is wrong when the child breaks a parent promise.

easyconcept

Give me a subclass that the compiler accepts but that still breaks the Liskov substitution principle. What rule does it break?

Substitutability is a claim about behaviour, and signatures carry none of it. A subclass that rejects an argument its supertype accepted has strengthened a precondition, which the compiler cannot see: the code type-checks, and it breaks callers that were written correctly against the base type.

mediumconcept

Where does encapsulation or polymorphism change a design, and how do you decide between composition and inheritance?

Encapsulation earns its place when a class owns an invariant that callers would otherwise each have to enforce, and polymorphism when a conditional grows with every new requirement. Composition versus inheritance is decided on evidence: how many axes vary, and whether every inherited operation is honest.

mediumconcept

What are the four pillars of OOP, and what is the difference between abstraction and encapsulation?

Encapsulation, inheritance, polymorphism and abstraction are worth stating as consequences rather than definitions - what each one buys you and what it costs. Abstraction decides what a type means to its caller; encapsulation protects how that meaning is upheld.

easyconcept

When you call an overridden method through a base-class reference, how does the runtime know which implementation to run?

The compiler cannot know, so it emits an indirect call through a per-class table of function pointers that the object carries a reference to. The lookup itself is a couple of memory accesses; the real cost is the optimisations the compiler cannot perform when the target is not known until run time.

mediumconcept