Skip to main content
ICT
Lesson A2 - Object Oriented Programming
 
Main   Previous Next
 

E. The Difference Between Objects and Classes page 7 of 10

  1. 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.

A class:

  • is a blueprint that defines attributes and methods.
  • is written by a programmer.
  • cannot be altered during program execution.
  • is named by a class name.

An object:

  • must belong to some class.
  • is an instance of that class.
  • exists during the time that a program executes.
  • must be explicitly declared and constructed by the executing program.
  • has attributes that can change in value and methods that can execute during program execution. (The class to which the object belongs defines theses attributes and methods.)
  • is most often referenced using an identifier.
  1. 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.

  2. 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.

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.