Inheritance allows one class (derived) to acquire properties/behaviors of another class (base).
Animal= base class witheat()Dog= derived class that reuseseat()and addsbark()
"Inheritance is an is-a relationship. A Dog is an Animal, so it can reuse Animal behavior and add specific behavior."
- Use inheritance for real is-a relationships.
- Prefer
publicinheritance for behavioral substitutability. - Don’t overuse inheritance when composition can do better.
- Ask first: "Do I need subtype polymorphism or just code reuse?"
- Keep base classes cohesive and behavior-focused, not data-heavy.
- Avoid fragile base class design by minimizing virtual surface area.