RosettaCodeData/Task/Polymorphism/Perl-6/polymorphism-1.pl6

19 lines
357 B
Raku

class Point {
has Real $.x is rw = 0;
has Real $.y is rw = 0;
method Str { $.perl }
}
class Circle {
has Point $.p is rw = Point.new;
has Real $.r is rw = 0;
method Str { $.perl }
}
my $c = Circle.new(p => Point.new(x => 1, y => 2), r => 3);
say $c;
$c.p.x = (-10..10).pick;
$c.p.y = (-10..10).pick;
$c.r = (0..10).pick;
say $c;