Create a class and its constructor and access it using a job in AX 2012

X++ Programming Language / OOP Concepts

440

Program:

 

// Class Declaration
public class Fruit
{
  str name;
  str color;
}

// New Method which act as a constructor
public void new(str _name, str _color)
{
    name = _name;
    color = _color;

}

// Get Color methos inside class Fruit
public str get_color()
{
    return color;
}

// Get Name methos inside class Fruit
public str get_name()
{
    return name;
}
 

Code: Job

This job will access the class


static void AccessClassFruit(Args _args)
{
    
     Fruit apple;
     apple = new Fruit("apple","red");
     info(strFmt("%1", apple.get_name()));
 
}
 

 

Output:

apple

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.