0

What case of inheritance will be correct?
When we inherit rectangle from square or square from rectangle or we shouldn't do inherit in this case?

Alex K.
  • 18
  • 2

2 Answers2

1

mathematically, a square is a rectangle.

but oo-wise, a square is not a rectangle because it will break the liskov substitution principle.

see also the circle ellipse problem.

Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
-1

Yes As per "Muhahhad Faizan Uddin" said square is always a rectangle, but vice versa is not always true. But if can see square if more of specific shape and rectangle is generalized term. So In my experience Square should Inherit rectangle class.