Menu
Coddy logo textTech

Execute Methods

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

To access methods in an object, we use:

MyClass myObj = new MyClass();
myObj.myMethod();

In the above example, we execute the method called myMethod in the object myObj which is an instance of MyClass class.

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 SecretMethod, in the main method, create an object for this class and call the secret method with the argument 5.

Try it yourself

using System;

class SecretMethod {
    public void secret(int x) {
        Console.WriteLine(x + " is the secret!");
    }
}

class Program {
    public static void Main(string[] args) {
        // Write code here
    }
}

All lessons in Basics of Classes and Objects in C#