RosettaCodeData/Task/Classes/EMal/classes.emal

31 lines
857 B
Plaintext

type Bear ^| the type system is informed about the new type,
| here we are in the static context
|^
model # instance context
text name # instance variable
^|
| in EMal the instance variables are ordered, and a default
| variadic constructor is provided by the runtime.
| Every value passed to the constructor sets the instance variable
| according to the order.
|^
fun makeNoise ← void by block # method of Bear
writeLine("Growl!")
end
end
type Cat
model
text noise
new by text noise # an explicit constructor
me.noise ← noise # we must use me to access instance variables
end
fun makeNoise ← void by block
writeLine(me.noise)
end
end
type Main
Bear bear ← Bear("Bruno") # creating a new instance
writeLine("The bear is called ", bear.name)
bear.makeNoise()
Cat("Meow").makeNoise()