Method definition

Method definition

Method is a subroutine.

Format is:


access-control method return-type method-name(arguments)

statements

endmethod


You can use the abbreviation em instead of endmethod.

In the class definition, it is possible to define methods of any number at any place outside the other member definitions.

access control

Access-control determines the access level by specifying a keyword either open or closed.

If it is open, you can invoke the method from outside the class definition. If it is closed, you can invoke the method only inside the class definition.

method

The method is a keyword which indicates this is a method. It must be present between the access-control and return-type.

return type

The return-type is a specification of a class which is returned.

You should specify a void if the method does not return a value.

method name

Identifier and embedded class name can use for the method name.

arguments

The argument is a pair of class name and identifier in parentheses. You can specify any number of such pairs. If there are two or more pairs, they must be separated by commas.


open method void sampleMethod()

open method void sampleMethod(int index)

open method void sampleMethod(int index, string message)


There are no special keywords to indicate that there are no arguments. If there are no arguments, you do not need to specify anything in parentheses.

statements

If the return type is void, statements are optional.

If the return type is not void, a return statement is required at a minimum.

endmethod

The endmethod is a keyword which indicates end of definition. You can use the abbreviation em instead of endmethod.

overload

You can define methods which has same name if number and class of arguments are different.

scope

A method generates a scope.

return

A method can return to invoker from anywhere by return statement. The return statement should return an instance of the class which is specified

Copyright © Rice All rights reserved.