27 Class declarations
A class models an entity with fields and behavior that can change.
norm
class Counter {
Integer value
Void increment() {
value = value + 1
}
}
main() {
Counter counter = Counter(value: 0)
counter.increment()
printLine(counter.value)
}Expected output:
text
1The labeled construction supplies value. Calling increment() mutates the same counter, and a later field read observes one. Methods keep state changes close to the entity they govern.
Try it: Call increment() twice and predict the result.
Precise rules: Reference.