PreviousNextIndex

METHOD statement

Defines a method of a class, declares a method prototype in an ABL interface, or overrides a method inherited from an ABL or .NET super class. A method is a class member that, when invoked by name, can execute code and return a value similar to a user-defined function. The description that follows begins with the general syntax for defining a method.

Note: This statement is applicable only when used in a class or interface definition (.cls) file.
Syntax

METHOD [ PRIVATE | PROTECTED | PUBLIC ] [ STATIC | ABSTRACT ]  
  [ OVERRIDE ] [ FINAL ]  
  { VOID | return-type } method-name  
  ( [ parameter [ , parameter ] ... ] ) : 
  method-body  

Use the following syntax to declare an interface method prototype:

METHOD [ PUBLIC ]  
  { VOID | return-type } method-name  
  ( [ parameter [ , parameter ] ... ] ) . 

Use the following syntax to declare an abstract method prototype:

METHOD [ PROTECTED | PUBLIC ] [ OVERRIDE ] ABSTRACT 
  { VOID | return-type } method-name  
  ( [ parameter [ , parameter ] ... ] ) . 

[ PRIVATE | PROTECTED | PUBLIC ]
[ STATIC ]
[ ABSTRACT ]
[ OVERRIDE ]
[ FINAL ]
VOID
return-type
AS-data-type
object-type-name
[ CLASS ]
[ EXTENT [ constant ] ]
method-name
( [ parameter [ , parameter ] ... ] )
method-body
method-logic
catch-block
END [ METHOD ]
Examples

The following example shows the definition of an instance method in a class (which might implement a method prototype declared in an interface, as depicted in the second example):

METHOD PUBLIC CHARACTER GetCustomerName (INPUT inCustNum AS INTEGER): 
  FIND ttCust WHERE ttCust.CustNum = inCustNum NO-ERROR. 
  IF AVAILABLE ttCust THEN 
    RETURN ttCust.CustName. 
  ELSE 
    RETURN ?. 
END METHOD. 

The following example shows the definition of a method prototype declaration in an interface (which can be implemented by an instance method definition in a class, as depicted in the first example):

INTERFACE acme.myObjs.Interfaces.ICustObj: 
  METHOD PUBLIC CHARACTER GetCustomerName (INPUT inCustNum AS INTEGER). 
END INTERFACE. 

For more examples of method definitions, including static and abstract methods, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.

Notes
See also

Class-based method call, CLASS statement, FUNCTION statement, INTERFACE statement, Parameter definition syntax, PROCEDURE statement, RETURN statement, Type-name syntax, USING statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex