The format of the setter definition is:
Access-control setter Setter-name(Argument)
It is a definition that starts with access control, followed by the keyword setter, and ends with the keyword endsetter.
You can define setters with different argument classes even if they have a same name. And, you can place them anywhere in the class definition.
An assignment to setter is automatically converted to a setter call.
The setter definition will generate a scope.
It specifies the access level of the setter using the keywords open or closed.
If you specify open, the setter can be called from outside of the class definition.
If you specify closed, the setter can only be used inside of the class definition.
It is a keyword that indicates that it is a setter definition. It must be specified next to access control.
It specifies the setter name after "setter". The naming rules for setter name is the same as for identifiers.
Exceptionally, you can use the name of the built-in class as the setter name.
Seeter argument is specified next to the Setter-name, it must be enclosed by parentheses.
An argument is a pair of class name and argument name. One argument is required for the setter. The argument class is the class of the value that can be assigned to the setter.
Since the setters are also distinguished in the argument class, you can define setters with the same name but different argument classes.
It is a keyword that indicates the end of the setter definition.
You can use the abbreviation "es" instead of "endsetter". Note that "es" is also a keyword.
Let's define setters in the example class.
open fitter example() // Default fitter.
x = 0;
y = 0;
open fitter example(int xx, int yy) // Fitter with two arguments.
x = xx;
y = yy;
ef // Abbreviation.
open setter X(int val)
x = val;
open setter Y(int val)
y = val;
es // Abbreviation.
The setter is called by an assignment expression.
example ex = new example();
ex.X = 10; // open setter X(int val)
ex.Y = 10; // open setter Y(int val)