Instantiation

Constructor

A constructor is a special method that runs automatically when an object is created from a class. Its job is to set up the object’s initial state.

  new Player("Alice")
  ┌─────────────────────┐
  │     constructor     │  ← runs automatically
  │  sets name = Alice  │
  └─────────────────────┘
  Player object ready

What a Constructor Does#

When you create an object, you often need to give it some starting values — a name, a score, a position. The constructor receives those values as arguments and stores them on the object.

Object

An object is a specific instance created from a class. The class is the blueprint; the object is the thing built from it.

You can create as many objects as you need from the same class. Each one is independent — it has its own copy of the class’s data, separate from every other instance.

  ┌─────────────────┐
  │  class Player   │  ← blueprint (defined once)
  └────────┬────────┘
           │ instantiate
     ┌─────┴──────┐
     ▼            ▼
 ┌────────┐   ┌────────┐
 │ Alice  │   │  Bob   │  ← objects (created at runtime)
 │ score:3│   │ score:1│    each has its own data
 └────────┘   └────────┘

Class vs Object#

This distinction confuses almost every beginner. Here’s the clearest way to think about it: