Section 12.15. Exercise


12.15. Exercise

You can find the answer to this exercise in "Answer for Chapter 12" in the Appendix.

12.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?




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

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