Menu
Coddy logo textTech

Create Objects

Lesson 8 of 12 in Coddy's Basics of Classes and Objects in C# course.

Now, to get the whole picture, let's learn about Objects!

As said before, object are instances of a class, and a class is a template for an object.

To create an object of a class, we use the new keyword:

MyClass myObj = new MyClass();

In the above example, we create an object called myObj of type class MyClass.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

You are given a code with a class named MyPoint, in the main method, create an object for this class and name it <strong>point</strong>.

Try it yourself

using System;

class MyPoint {
    public int x = 5;
    public int y = 10;
}

class Program {
    public static void Main(string[] args) {
        // Write code here
        
        // Don't change below this line
        Console.WriteLine("(" + point.x + ", " + point.y + ")");
    }
}

All lessons in Basics of Classes and Objects in C#