An object is very closely associated with the class to which it belongs. An object has attributes as defined by its class. An object’s behavior is restricted by the methods that are included in its class. However, there are significant differences between objects and classes.
Classes can be compared to a blueprint. The purpose of a blueprint is to provide a guide for creating things, just as the purpose of a class is to guide the creation of objects. A single blueprint is designed to produce a single basic type of object. Similarly, the objects from the same class all share common characteristics.
Each object must belong to one particular class, and the object is said to be a member of the class to which it belongs. The myPencil
object that was created earlier belongs to the DrawingTool
class. This means that the myPencil
object is permitted to perform DrawingTool
methods (operations). This also means that the myPencil
object is not permitted to perform DrawSquare
methods; these methods are designed for a different kind (class) of object.