9.15 Exercise


The answers for all exercises can be found in Section A.8.

9.15.1 Exercise [45 min]

Give the Animal class the ability to get and set the name and color . Be sure that your result works under use strict . Also make sure your get methods work with both a generic animal and a specific animal instance. Test your work with:

 my $tv_horse = Horse->named("Mr. Ed"); $tv_horse->set_name("Mister Ed"); $tv_horse->set_color("grey"); print $tv_horse->name, " is ", $tv_horse->color, "\n"; print Sheep->name, " colored ", Sheep->color, " goes ", Sheep->sound, "\n"; 

What should you do if you're asked to set the name or color of a generic animal?



Learning Perl Objects, References & Modules
Learning Perl Objects, References, and Modules
ISBN: 0596004788
EAN: 2147483647
Year: 2003
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net