Objects and Classes

Objects in the real world are made up of many other objects (in OOP speak this is called aggregation or containment). For example, a car object contains tire objects, an engine object, a steering system object, a breaking system object, and so forth. Organizing a program into a hierarchy of objects helps us conceptualize it. Essentially, you break down the program into interrelated objects, which are in turn broken down into other objects. This is called inheritance.

A class is a template for creating objects by defining their behavior and attributes. Thus, a car class defines the behaviors of a car, such as

  • Moving forward or backward

  • Breaking

  • Turning

It also defines the car's attributes, such as

  • Make

  • Model

  • Color

  • Year

  • Two door or ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.