Objects and Classes

Learn about objects and classes in object-oriented programming.

An object is a collection of attributes with associated behaviors. But how do we differentiate between types of objects?


Apples and oranges are both objects, but it is a common adage that they cannot be compared. Apples and oranges aren’t modeled very often in computer programming, but let’s pretend we’re making an inventory application for a fruit farm. To facilitate this example, we can assume that apples go in barrels and oranges go in baskets.

The problem domain we’ve uncovered so far has four kinds of objects: apples, oranges, baskets, and barrels. In object-oriented modeling, the term used for a kind of object is class. So, in technical terms, we now have four classes of objects.

It’s important to understand the difference between an object and a class. Classes describe related objects. They are like blueprints for creating an object. You might have three oranges sitting on the table in front of you. Each orange is a distinct object, but all three have the attributes and behaviors associated with one class: the general class of oranges.

Association between classes

The relationship between the four classes of objects in our inventory system can be described using a Unified Modeling Language (from now on referred to as just UML) class diagram. Here is our first class diagram:

Get hands-on with 1200+ tech skills courses.