RosettaCodeData/Task/Classes/Blz/classes.blz

17 lines
349 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# Constructors can take parameters (that automatically become properties)
constructor Ball(color, radius)
# Objects can also have functions (closures)
:volume
return 4/3 * {pi} * (radius ** 3)
end
:show
return "a " + color + " ball with radius " + radius
end
end
red_ball = Ball("red", 2)
print(red_ball)
# => a red ball with radius 2