You can have a super class Shape, Square and Rectangle are two children class, but can you have Square subclass Rectangle as Square is a special Rectangle with four sides equal?
I tried to examine using the principle that whenever a super class is used, it should be able to be replaced by its child class, but if a child class is used, it may not be able to be replaced by its super class. Looks like it is fine, but I always feel Square cannot be a child of Rectangle for some reason? Can anyone shed me some light?
You are referring to the Liskov Substition Principle
Specific to your question:
In plain English, you can’t use a Square where a Rectangle is expected because a Square has behavior that a Rectangle doesn’t. If someone is trying to use what they think should be an instance of Rectangle, but it’s really an instance of Square, they might set the Width and be surprised that the Height automatically changes (unexpected side effect).