Getter definition

Getter definition

Getter is a subroutine which is invoked with the reference expression format.

Format is:


access-control getter return-type getter-name

statements

endgetter


You can use the abbreviation eg instead of endgetter.

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

Getter's main aim is the provision of way of access to a field.

access control

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

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

getter

The getter is a keyword which indicates this is a getter. 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.

getter name

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

statements

At a minimum, a return statement is required.

endgetter

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

scope

A getter generates a scope.

return

A getter 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.