ODNYX.

Classes and Objects

Video Tutorial Coming Soon — Channel Production Underway

Java is an object-oriented language, which means programs are built around objects — bundles of data (fields) and behavior (methods) modeled on real-world things.

Tip: think of a class as a blueprint, and an object as one specific thing built from that blueprint.

Defining a class

public class Car {
    String color;
    int speed;

    void accelerate() {
        speed += 10;
    }
}

Creating objects from a class

Car myCar = new Car();
myCar.color = "red";
myCar.accelerate();
System.out.println(myCar.speed); // 10

You can create as many objects as you need from the same class — each one holds its own independent copy of the fields.

What’s next

Next up: Polymorphism, one of the core ideas in object-oriented Java — and it comes in two distinct flavors, which we’ll cover as their own sub-topics.

📋 Object-Oriented Programming Interview Questions