RosettaCodeData/Task/Classes/Pluto/classes.pluto
2026-04-30 12:34:36 -04:00

22 lines
554 B
Text

class bear
-- Constructs a Bear instance passing it a name
-- which is stored in a private field to avoid external mutation.
function __construct(private name) end
-- Property to get the name
function name() return self.name end
-- Method to make a noise.
function make_noise()
print("Growl!")
end
end
-- Create a new bear instance and assign a reference to it
-- to the variable b.
local b = new bear("Bruno")
-- Print the bear's name.
print($"The bear is called {b:name()}.")
-- Make a noise.
b:make_noise()