Classes and Objects

Lesson 11 of 20

From blueprint to living object — build a Car with new, start its engine and watch the call stack work.

The big picture

Blueprints and houses

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

class = blueprint

It declares fields (data) and methods (behavior), but holds no live data itself.

object = real thing

new Car("Civic") builds an instance that owns its own copy of every field.

constructor

A special method, named after the class, that runs once and sets up the new object.

methods act

drive() can change fields — each car changes only its own speed.