Home› X++ Programming Language› / Programs / Create a class in AX using x++ code
🚀 Programming Example

Create a class in AX using x++ code

773 Views
Beginner
Code Snippet
Create a class in AX using x++ code,

💻 Program Code

//How to create a class and access it from another Job
//Class Declaration: 
public class Class1
    {
        str firstName;
    }
  
//Method:
public void setFirstName(str _firstName)
{
        firstName = _firstName;
}
 

// Method: 
public str getFirstName()
{
        return firstName;
}
 
// Job: 
/*
We will access our class using this below JOB
Class1 is present in the class section
*/

public static void runYourOwnClass(Args _args)
{
        Class1 c1;
        str name;
        c1 = new Class1();         
        c1.setFirstName("My Name");
        name  = c1.getFirstName();
        info(strFmt("%1",name));    
}

🖥 Program Output

                                My Name
                            

📘 Explanation

No
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.