Introduction to Objects

Introduction to Objects
Introduction to Objects
CONCEPT

Objects are instances of a class. They are created with a definition statement after the class has been declared.

EXPLANATION

A class declaration is similar to the blueprint for a house. The blueprint itself is not a house, but is a detailed description of a house. When we use the blueprint to build an actual house, we could say we are constructing an instance of the house described by the blueprint. If we wish, we can construct several identical houses from the same blueprint. Each house is a separate instance of the house described by the blueprint. This idea is illustrated in Figure Below.


A class declaration serves a similar purpose. It describes what the objects created from the class will look like when they are constructed. Each object created from it is called an instance of the class.
Class objects are created with simple definition statements, just like variables. For example, the following statement defines circle1 and circle2 to be two objects of the Circle class:
Circle circle1,
           circle2;
Defining a class object is called the instantiation of a class. The objects circle1 and circle2 are two distinct instances of the Circle class, with different memory assigned to hold the values stored in their member variables.
Previous
Next Post »