Thuta Learning
IntermediateProgrammingbeginner

Classes & Objects

Relax. We'll talk through this in plain words — no textbook voice.

Class is a blueprint for creating an object, and is an actual instance created from a class. A class can hold fields/properties and methods.Object

csharp
class Car
{
    public string Color = "red";

    public void Drive()
    {
        Console.WriteLine("The car is driving.");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Car myCar = new Car();
        Console.WriteLine(myCar.Color);
        myCar.Drive();
    }
}

What this code does

  • Car class is the blueprint for a car object.
  • Color field stores the object's data.
  • Drive() method shows the object's behavior.
  • new Car() creates a new Car object.
You should see
red The car is driving.
Classes & Objects | Thuta Learning