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.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyYou 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#
1Introduction
Introduction