Closed BoAi01 closed 1 year ago
Derived classes must be substitutable for their base classes.
If the child class is more restrictive, substituting the parent with the child would result in unexpected behaviors.
You can read more here!
Alright, thanks. I would really think it depends on how we define "restrictive" though. If A can substitute B (A is a sub-class of B) means A is less restrictive, this statement makes sense, yes.
Thanks!
Yup, don't equate restrictive with specialized. The child classes can be more specialized without being more restrictive than the parent class.
May I know why the parent class is more restrictive than the child class? I thought inheritance makes it more "specialized".