polserver/testsuite/escript/classes/doc-sample-02.src
Kevin Eady 0fa1b893a0 Update core-changes, break-changes for classes support (#719)
* Format testsuite escript

* Format testsuite pol

* Update docs
Switch "attributes" to "members" to better align with Escript terms.

* Add core-changes, breaking-changes
2024-10-10 18:06:04 +02:00

25 lines
564 B
Text

class Animal()
var animal_count := 0;
function Animal( this, type )
this.type := type;
this.id := ++animal_count;
endfunction
function Print( this )
basicio::Print( $"Animal {this.id} is a {this.type}" );
endfunction
endclass
var dog := Animal( "dog" );
print( dog.id ); // Output: 1
dog.Print(); // Output: Animal 1 is a dog
Animal::Print( dog ); // Output: Animal 1 is a dog
print( Animal::animal_count); // Output: 1
var cat := Animal( "cat" );
cat.Print(); // Output: Animal 2 is a cat
// print( animal_count ); // Compiler error!