Saturday, May 7, 2011

CLASSES AND OBJECTS

People new to OO programming often have difficulty distinguishing what are called classes from what are
called instances. A class is a specification, a blueprint, or maybe even a concept, like vehicle; an instance is a
specific example of a class. From the class Automobile, one can build or identify particular cars. My Ford
with vehicle ID 1FABP64T1JH100161 is said to be an instance of the class Automobile.
Often the word object is used as a synonym for the word instance. One also says that my Ford is an object
of the class Automobile. This can be confusing, especially at first, because Java, like some other OO
languages, also recognizes a class called Object (capital O). In fact, every class in Java inherits from the class
Object (we will discuss inheritance soon); the class Object is the root of the Java class hierarchy. Though
the use of the word in two senses can be confusing, generally one should understand the word “object” to mean
“instance,” unless the word “Object” is capitalized.
We say that <an instance> “is” <a class>. Some writers say that an “is-a” relationship exists between
an instance and its class. For instance, my Ford is an Automobile.

No comments:

Post a Comment