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.
In a nutshell, classes are the blueprints for objects. Each class, or blueprint, is designed to produce many objects, all of a single type.
On the other hand, each object belongs to a single class. The myPencil
object that was created earlier belongs to the DrawingTool
class; myPencil
, therefore, is the same type as all other objects created from DrawingTool
, and can perform all of the methods a DrawingTool
can. On that front, it cannot call methods from or hold attributes defined in the Math
class, for obvious reasons.
Last modified: December 12, 2022
Back to Putting It All TogetherDark Mode
Outline