← Back to C# Course | Chapter 6: OOP Basics | Lesson 2 of 7

Objects

In this page:

  1. Objects

Objects

An object is a concrete instance of a class, created with the new keyword. Each object has its own independent copy of the class's instance fields. You can create many objects from the same class, each representing a distinct entity.

Note: Every object created with new gets its own memory, so changing one object never affects another.

Example: Objects

markup
using System;

class Point
{
    public int X;
    public int Y;
}

class Program
{
    static void Main(string[] args)
    {
        Point p1 = new Point { X = 1, Y = 2 };
        Point p2 = new Point { X = 5, Y = 9 };

        Console.WriteLine($"({p1.X}, {p1.Y})");
        Console.WriteLine($"({p2.X}, {p2.Y})");
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.