Objects
In this page:
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
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})");
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: