Chapter 3. Inheritance
Inheritance is a "is a kind of" relationship and the cornerstone of object-oriented programming. For example, a rectangle, an ellipse, and a triangle are "a kind of" shape. Without inheritance, you would have to fully and independently implement the rectangle, ellipse, and triangle classes. It is better to extrapolate the common elements of any shape and place those elements into a general class. That general class then can be inherited into the specific shape classes. This avoids having to implement the same code in every shape class. Code reuse is one of the primary benefits of inheritance. The general class is called a base class. The specific classes, such as rectangle, ellipse, and triangle, are considered derived classes. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access