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 are the signs that code violates the Liskov Substitution Principle?

    Subclasses that throw UnsupportedOperationException, override a method to do nothing, or callers that must check instanceof before using a parent-typed object.

    IntermediateQuick answer1 min read
  2. Why does Square extending Rectangle violate the Liskov Substitution Principle?

    A Square must keep width and height equal, so setting one changes the other. Code written for any Rectangle, expecting independent sides, gets wrong results when given a Square.

    IntermediateQuick answer1 min read