ptg7068951
134 HOUR 10:Creating Your First Object
When you run the program, you should see output matching Figure 10.4.
FIGURE 10.4
The output of theModemTester
program.
The following things are taking place in Listing 10.5:
. Lines 3–4: Two new objects are created—a CableModemobject called
surfBoardand a DslModemobject called gateway.
. Line 5: The speedvariable of the CableModemobject named
surfBoardis set to 500000.
. Line 6: The speedvariable of the DslModemobject named gatewayis
set to 400000.
. Line 8: The displaySpeed()method of the surfBoardobject is
called. This method is inherited from Modem—even though it isn’t
present in the CableModemclass, you can call it.
. Line 9: The connect()method of the surfBoardobject is called.
. Line 11: The displaySpeed()method of the gatewayobject is called.
. Line 12: The connect()method of the gatewayobject is called.
Summary
After creating your first class of objects and arranging several classes into a
hierarchy, you ought to be more comfortable with the term object-oriented
programming(OOP). You learn more about object behavior and attributes in
the next two hours as you start creating more sophisticated objects.
Terms such as program, class, and object make more sense as you become
more experienced with this style of development. OOPis a concept that
takes some time to get used to. When you have mastered it, you find that
it’s an effective way to design, develop, and debug computer programs.