Interview Q&A / Object-Oriented Programming

INTERVIEW Q&A · 69 QUESTIONS

Object-Oriented Programming interview questions

The four pillars, interfaces, abstract classes and design basics.

  1. What is a covariant return type in method overriding?

    An overriding method may return a more specific type (a subclass) than the parent's method declared. Callers using the child type then avoid casting.

    AdvancedQuick answer1 min read
  2. What rules must an overriding method follow to respect the Liskov Substitution Principle?

    It must accept at least what the parent accepts, promise at least what the parent promises, and throw no new kinds of failure. Weaker preconditions, stronger postconditions, same invariants.

    AdvancedQuick answer1 min read