Home » Microsoft » MB6-704 » Which code segment should you insert at line 21?
You have the following X++ code: (Line numbers are included for reference only.)
Method l and method2 are in Class l. Method3 is in Class2.
You need to set variablel for class l Obj to a value of 5.
Which code segment should you insert at line 21?
A. classl Obj.methodl(5);
B. new Classl( ).methodl(5);
C. classl Obj.variable1 = 5;
D. this. variable l =5:
Correct Answer: A
Explanation/Reference:
All classes are public, but all member variables are implicitly private. Use a public Setter Accessor method, here method1, on Obj1 to change the variable of the other class.
Example:
Add a Setter Accessor Method
Follow these steps to add a method that sets the value of a member variable:
1. Right-click the Class1 node, and then click New > Method.
2. Rename the method1 node to setFirstName.
3. In the code Editor window, paste in the following X++ code for the method.
X++ public void setFirstName(str _firstName)
{ firstName = _firstName;
}
Reference: Declaration of Classes [AX 2012]