Compartilhar via


Method Modifiers

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

There are several modifiers that can be applied to method declarations. Some of the modifiers can be combined (for example, final static).

The following table describes the method modifier keywords of the X++ language.

Modifier

Description

abstract

The method is declared but not implemented in a parent class. The method must be overridden in subclasses.

If you try to create an object from a subclass where one or more of the abstract methods belonging to the parent class have not been overridden, you will get a compiler error.

Note

Classes can also be abstract. Sometimes a class represents an abstract concept, but it should not be instantiated: Only subclasses should be instantiated. Such base classes can be declared abstract. Consider the case where the programmer wants to model the concept of an account. Accounts are abstract—only derived classes (ledger accounts and so on) exist in the real world. This would be a clear case for declaring the Account class abstract.

client

Establishes the location where the method is to be executed (on the client).

Can only be used on static methods. If the method is not static, specify the location by using the class property RunOn.

display

Indicates that the method's return value is to be displayed on a form or a report. The value cannot be altered in the form or report.

The return value is typically a calculated value, for example, a sum.

For more information about the display and edit modifiers, see Using the display Method Modifier.

edit

Indicates that the method's return type is to be used to provide information for a field that is used in a form. The value in the field can be edited.

final

Indicates that the method cannot be overridden in any class that derives from its class.

public

Methods that are declared as public are accessible anywhere the class is accessible and can be overridden by subclasses. Methods that have no access modifier are implicitly public.

protected

Methods that are declared as protected can only be called from methods in the class and in subclasses that extend the class where the method is declared.

private

Methods that are declared as private can be called only from methods in the class where the private method is declared.

server

Establishes the location where the method is to be executed (on the server).

Can only be used on static methods. If the method is not static, you need to specify the location using the class property RunOn.

static

Specifies that the method is a class method and does not operate on an object.

static methods cannot refer to instance variables and are invoked by using the class name rather than on an instance of the class (MyClass::aStaticProcedure()).

For more information, see Static Methods.

See also

Declaration of Methods

Best Practices for Method Modifiers

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.