Introduction to Object-Oriented Programming

Lesson 12 of 20

Classes are blueprints and objects are the houses — build your first Dog, then make it speak for itself.

The big picture

Blueprints and houses

A class is a blueprint; an object is a house built from it. One blueprint, many houses.

class = blueprint

Defines which data (members) and behaviour (methods) every object of that type will have.

object = house

One concrete instance built from the blueprint. Rex and Buddy are two Dogs from one class.

Data + behaviour together

An object carries its own fields (name, age) and its own actions (speak) — one tidy bundle.

public:

A label inside the class: everything below it may be used from outside, like myDog.name.