The accepted answer is not a counterexample.
Liskov Principle: Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
Actually, the accepted answer is not a counterexample for the Liskov principle. A square naturally is a specific rectangle, so it makes perfect sense that inherits from the class rectangle. You simply need to implement it in this way:
@Override public void setHeight(double height) { this.height = height; this.width = height; // since it's a square } @Override public void setWidth(double width) { setHeight(width); } So, having provided a good example, this, however, is a counterexample:
class Family: -- getChildrenCount() class FamilyWithKids extends Family: -- getChildrenCount() { return childrenCount; } // always > 0 class DeadFamilyWithKids extends FamilyWithKids: -- getChildrenCount() { return 0; } -- getChildrenCountWhenAlive() { return childrenCountWhenAlive; } In this implementation, DeadFamilyWithKids cannot inherit from FamilyWithKids since getChildrenCount() returns 0, while from FamilyWithKids it should always return something greater 0.