Understanding Inheritance
A big advantage to OOP is inheritance, which enables one object to inherit behavior and attributes from another object.
When you start creating objects, you sometimes find that a new object you want is a lot like an object you already have.
What if David Lightman wanted an object that could handle error correction and other advanced modem features that weren’t around in 1983 when WarGames was released? Lightman could create a new ErrorCorrectionModem object by copying the statements of the Modem object and revising them. However, if most of the behavior and attributes of ErrorCorrectionModem are the same as those of Modem, this is a lot of unnecessary work. It also means that Lightman would have two separate programs ...
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