use 5.014; package Car { sub new { bless \@_, shift } sub go { say "brmm!" } } package Spacecraft { sub new { bless \@_, shift } sub go { say "whoosh!" } } my $vehicle = int(rand 2) ? Car->new : Spacecraft->new; # Is $vehicle a car or a spacecraft? # It doesn't matter! $vehicle->go;
In reply to Re: How to use polymorphism in perl
by tobyink
in thread How to use polymorphism in perl
by ramu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |