I need some serious help. Been trying to figure out inheritance. Was given an assignment to practice inheritance. the code given was.
use v5.10.0; use warnings; use strict; package Animal; sub new { my $class = $_[0]; my $self = {text => "I am an abstract animal.\n"}; return bless($self, $class); } sub speak { my $self = shift; print $self->{"text"} } package Duck; our @ISA = qw(Animal); # qw(Animal) je ekvavilentno ("Animal") sub new { return bless({text => "I am a a duck.\n"}, shift); }
So this is the given code and I'm just supposed to make another package named Cow, Horse, etc. However reading online this is different from the stuff I had and the code doesn't print out anything when running and testing it. From what I gathered it's supposed to print "I am a duck" but it does nothing at all.
I apologize in advance if this is a newbie question but i really can't figure it out tried asking my peers but no one new anything. Thanks in advance for any help.
In reply to [Resolved]Perl inheritance by ivanovic3001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |