Setter definition

Setter definition

Setter is a subroutine which is invoked with the assignment statement format.

Format is:

access-control setter setter-name(argument)



You can use the abbreviation es instead of endsetter.

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

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

access control

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

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


The setter is a keyword which indicates this is a setter. It must be present between the access-control and setter-name.

setter name

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


The argument is a pair of the class name and identifier which is surrounded by parentheses.


Statements are optional. Namely, a setter without statements is permitted.


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


You can define setters which has same name if class of argument is different.


A setter generates a scope.


A setter can return to invoker from anywhere by return statement. The return statement of the setter should not return an instance. If the control has reached the endsetter without encountering a return statement, it returns to invoker.

Copyright © Rice All rights reserved.