Define a class constructor
- Last Updated: October 13, 2023
- 1 minute read
- OpenEdge
- Version 12.2
- Documentation
A class definition contains at least one constructor. The syntax for defining a constructor for a class is:
constructor <access-mode> <class-name>
( [input <parameter> as <type-name>][,…]):
<body of constructor>
end constructor.
|
Syntax Element |
Description |
|
access-mode |
Specifies whether the constructor will be available
to other parts of an application. A best practice is to define the
constructor as |
|
class-name |
Must match the name of the class in the class definition |
|
type-name |
Can be one of the built-in or user-defined types. |
|
parameter |
The value that is used to set the property. It must match the type of the property. |
You can use the New Constructor wizard to generate the code for a constructor (right-click, then select Source > New Constructor). If the constructor takes parameters, you must manually add them to the definition.
- Use a no-argument constructor and then use a
PUBLICmethod to initialize the data members of the instance. - Use a constructor with parameters and use the parameters to initialize the data members of the instance in the body of the constructor.
For more information, see CONSTRUCTOR statement.