METHOD Verb
Syntax
METHOD accesslevel {STATIC} {typename} methodname(parameterlist)
Description
In BBj 6.0 and higher, the METHOD verb marks the beginning of a Custom Object method definition, which must end with a METHODEND verb.
Parameter |
Description |
accesslevel |
The method access level must be specified, and must be PUBLIC, PRIVATE or PROTECTED. A PRIVATE method is only visible within the class definition. A PROTECTED method is visible to code within the class definition, and in methods of classes that extend the class. A PUBLIC method can be accessed from all code, including code in other files. |
STATIC |
If specified, this indicates that the method being defined is a static method. A static method can only access fields that are declared static. Any attempt to access a non-static field will generate a runtime error. Static methods can be accessed directly against the class name; there's no need to instantiate an instance of the class. |
typename |
The type name specifies the data type returned by the method. If the method name corresponds to the class name, this method is a constructor, and the type name must not be specified. For all other method names, the type name must be specified, and can be any of the following:
|
methodname |
The method name must begin with a letter or underscore and can contain any combination of letters, numbers and underscores. |
parameterlist |
A comma-delimited list of zero or more parameters. Each parameter consists of a parameter type, followed by white space, followed by a parameter name. The parameter type can be any of the following:
The parameter name must begin with a letter or underscore, can contain any combination of letters, numbers, and underscores, and must specify a suffix compatible with the specified parameter type, consistent with standard BBx variable rules:
|
Notes
All BBj Custom Object names (interface name, class name, method name, field name) are case-sensitive.
The METHOD verb must be the only statement on the line (with one exception: it can end with a ; REM comment).
The METHOD verb is a syntax error unless the program also contains a METHODEND verb on a subsequent line.
The METHOD verb may not be nested within another METHOD.
A method definition (a block of code between METHOD and METHODEND) defines a variable scope. The only variables that are visible within that scope are the parameters specified in the method parameter list and the fields defined in the class. Labels and local variables in a method are only visible within that method.
The method name together with its parameter list is known as the “method signature”. Methods with the same name, but different parameter lists are considered unique and may coexist. The return type is not part of the method signature.Example 1
|
Example 2 (BBj 18.0 and higher)
|