RosettaCodeData/Task/Polymorphism/Sidef/polymorphism-2.sidef

13 lines
540 B
Plaintext

pp(Point.new); # => Point at 0,0
var p = Point(1, 2); # create a point
pp(p); # => Point at 1,2
say p.x; # => 1
p.y += 1; # add one to y
pp(p); # => Point at 1,3
var c = Circle(4,5,6); # create a circle
var d = c.clone; # make a clone of it
d.r = 7.5; # and change the radius to 7.5
pp(c); # => Circle at 4,5 with radius 6
pp(d); # => Circle at 4,5 with radius 7.5