Skip to content
AgileLogics

Programming glossary

Object

A specific instance created from a class, with its own data but the behavior defined by that class.

Picture a dealership with twenty cars of the same model. They were all built to one specification, so every car has a steering wheel, four doors and an engine that starts the same way. Still, each has its own colour, mileage and registration number, and driving one does not add kilometres to the others. In programming, those individual cars are objects, and the shared specification is their class.

An object bundles two things together: state, meaning the values stored in its fields, and behaviour, meaning the methods you can call on it.

Example

class Car {
    String colour;
    int mileage = 0;
    Car(String colour) { this.colour = colour; }
    void drive(int km) { mileage += km; }
}

// elsewhere, for example inside a main method:
Car first = new Car("red");
Car second = new Car("blue");
first.drive(120);
System.out.println(first.mileage + " " + second.mileage); // 120 0

Both cars come from the same class, but first.drive(120) changes only the first car's mileage. Each object keeps a separate copy of the fields.

Objects and references

In Java, Python, JavaScript and PHP, a variable that holds an object usually stores a reference to it rather than a full copy. Write Car third = first; and both names point at the same car, so driving third also changes first.mileage. This catches many beginners out. When you need a genuine duplicate, create a new object or copy the existing one explicitly.

Object vs class

A class is code you write; an object exists only while the program is running. You can think of new Car("red") as the moment the specification becomes something real in memory. JavaScript adds a looser meaning of the word: { name: "Ada" } creates an object directly, with no class involved at all.

Further reading

Last updated