CONSTRUCTOR statement
- Last Updated: October 30, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
CONSTRUCTOR statement
Syntax
This is the syntax for defining a class constructor:
|
Element descriptions for this syntax diagram follow:
- [ PRIVATE | PACKAGE-PRIVATE | PROTECTED| PACKAGE-PROTECTED |PUBLIC | STATIC ]
- Specifies the access mode for an instance constructor or
STATICto specify the static constructor. The default access mode for an instance constructor isPUBLIC.PRIVATEinstance constructors can be invoked by another constructor defined in the class using theTHIS-OBJECTstatement. APRIVATEconstructor can also be invoked by an instance of the defining class.PROTECTEDinstance constructors can be invoked by another constructor defined in the class and by a constructor defined in a subclass of the defining class using theSUPERstatement. APROTECTEDconstructor can be invoked by an instance of the defining class or a subclass. APACKAGE-PRIVATEconstructor can be called from the defining class or any class within its package. This is done via theSUPERstatement within another constructor or using theNEWstatement or function elsewhere. APACKAGE-PROTECTEDconstructor can be called from the defining class, from a subclass, or from any class within its package. This is done via theSUPERstatement within another constructor or using theNEWstatement or function elsewhere.PUBLICconstructors can be invoked by another constructor defined in the class, by a constructor defined in a subclass of the defining class, and by other classes and procedures that instantiate the defining class using theNEWfunction,NEWstatement, orDYNAMIC-NEWstatement. - class-name
- The name of the class stripped of any relative path information. This
is the class-name portion of the class-type-name defined by the
CLASSstatement. - [ parameter [ , parameter]...]
- Any parameters that you define for an instance constructor. You cannot define parameters for a static constructor. If this instance constructor overloads another instance constructor definition in the class, ABL must be able to disambiguate the two constructors by the number, data types, or modes of their parameter definitions (their signatures). For more information on the syntax of parameter and how to define overloaded constructor signatures, see the Parameter definition syntax reference entry in ABL Reference.
- constructor-body
- The logic of the constructor, which can be composed of any statements
currently allowed within a procedure block along with syntax restricted to methods. In
an instance constructor only, additional statements allowed include the
SUPERstatement, which invokes an instance constructor defined in the immediate super class, and theTHIS-OBJECTstatement, which invokes another instance constructor defined in the current class. In a static constructor, you can only access other static members defined within the current class hierarchy in addition to local method data; instance members defined within the current class hierarchy are inaccessible. However, in an instance constructor, constructor-body statements can access static members as well as other instance members. In general, the constructor logic is typically used to initialize accessible data members and properties of the class.
Adding
a constructor to the acme.myObjs.CustObj sample
class definition results in the following code:
|