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

19 lines
357 B
Raku
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
class Point {
2016-12-05 22:15:40 +01:00
has Real $.x is rw = 0;
has Real $.y is rw = 0;
2013-04-10 23:57:08 -07:00
method Str { $.perl }
}
class Circle {
has Point $.p is rw = Point.new;
2016-12-05 22:15:40 +01:00
has Real $.r is rw = 0;
2013-04-10 23:57:08 -07:00
method Str { $.perl }
}
2016-12-05 22:15:40 +01:00
my $c = Circle.new(p => Point.new(x => 1, y => 2), r => 3);
2013-04-10 23:57:08 -07:00
say $c;
$c.p.x = (-10..10).pick;
$c.p.y = (-10..10).pick;
$c.r = (0..10).pick;
say $c;