Workshop: Creating an Object
To see a working example of classes and inheritance, you will create classes that represent two types of objects: cable modems, which will be implemented as the CableModem class, and DSL modems, which will be implemented as the DslModem class.
For the sake of simplicity, the workshop will focus on a few simple attributes and behavior for these objects:
Each object should have a speed and be able to display it when asked.
Each object should be able to connect to the Internet.
One thing that cable modems and DSL modems have in common is that they both have a speed. Because it is something they share, it could be put into a class that is the superclass of both the CableModem and DslModem classes. Call this class Modem ...
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