Relating Objects to Java Classes

   

So far, the term object has been treated somewhat generically and it has been used a little loosely when referring to the code examples. Now classes need to be brought into the discussion to make it more concrete with respect to Java. Object data types are defined in Java using classes, like the Car class shown previously. In the software realm, objects are instances of those classes.

A class can be thought of as a template for creating an object. In the car example, SaturnSL2 is a class, not an object. It is a template for creating car objects that are of that type (a particular make and model in this case). If you go to a car dealership and ask to see a Saturn SL2, you are using a type (the class) to describe what variety of car you want, but you are not yet referring to a particular object. Once the dealer takes you to the SL2 section of the car lot, the cars you see are the objects. They are each unique, but they were created from the same template, or class. The red SL2 with a tan interior that you select to test drive and purchase is an object that is an instance of the SaturnSL2 class.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net