10. Constructors
Defining a constructor for a class: You can add a constructor for a class by adding the <constructor> specifier on the function name. Instead of specifying a return type on the function, the function is assigned the class name followed by any initialization of fields. A class can have more than one constructor.
<constructor> specifier on the function name. Instead of specifying a return type on the function, the function is assigned the class name followed by any initialization of fields. A class can have more than one constructor.class1 := class:
Property1 : int
MakeClass1<constructor>(Arg1:int) := class1:
Property1 := Arg1
Main():void =
X := MakeClass1(1)
F := MakeClass1()
Z := F(2)MakeOtherClass1<constructor>(Arg1 : int) := class1:
let:
OnePlusArg1 := Arg1 + 1
block:
DoSomething(OnePlusArg1)
Property1 := OnePlusArg1
block:
DoOtherStuff()
Last updated