If you've already looked at classes in Java or Python, C++ classes will feel familiar in spirit, though the syntax carries its own particular flavour, with a couple of ideas that are genuinely specific to C++.

A basic class

class Dog {
public:
    std::string name;
    int age;

    void bark() {
        std::cout << name << " says woof!" << std::endl;
    }
};

Dog myDog;
myDog.name = "Rex";
myDog.age = 3;
myDog.bark();

public and private

The public: label controls which members outside the class are allowed to access. Anything under private, the default if you write nothing at all, can only be used from inside the class itself. Making fields private and only exposing them through methods, the same encapsulation idea found in most object-oriented languages, is generally considered good practice here too, even though the example above kept things public to stay simple.

Constructors

class Dog {
public:
    std::string name;
    int age;

    Dog(std::string dogName, int dogAge) {
        name = dogName;
        age = dogAge;
    }

    void bark() {
        std::cout << name << " says woof!" << std::endl;
    }
};

Dog myDog("Rex", 3);

A constructor shares the class name and runs automatically when an object is created, letting you set up its starting values in one step rather than assigning each field one at a time afterward.

The destructor: something Java and Python don't really have

class Dog {
public:
    ~Dog() {
        std::cout << "A Dog object is being destroyed" << std::endl;
    }
};

A destructor, marked with a tilde before the class name, runs automatically when an object is about to be destroyed, whether that's because it went out of scope or was explicitly deleted. This is a genuinely C++-specific idea, tied closely to how C++ manages memory manually rather than relying on automatic garbage collection the way Java and Python do — the tutorial on the stack and the heap goes deeper into exactly that.

Inheritance

class Puppy : public Dog {
public:
    void bark() {
        std::cout << name << " yips!" << std::endl;
    }
};

The colon followed by public Dog means Puppy inherits everything from Dog, and here it overrides bark with its own version, replacing the parent's behaviour rather than reusing it.

A small honest note

C++ classes have more moving parts than most languages ask of you upfront: constructors, destructors, access levels, and eventually things like copy constructors that this tutorial hasn't even touched yet. Don't feel like you need all of it on day one. Start with the basics shown here, write a few small classes, and let the rest come as you actually need it.