


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



#include
class Animal def initialize (name = "Anonymous", legs = 0) @name = name; @legs = legs end def speak "Hi" end def kind self.class.to_s end def inspect @name + " is a " + kind + " who has " + @legs.to_s + " legs and says "" + speak + "."" end end class Dog < Animal def initialize (name = "Fido", breed = "Mutt") super(name, 4); @breed = breed end def speak "Arf" end def kind super + " (a " + @breed + ")" end end class Parrot < Animal def initialize (name = "Polly") super(name, 2) end def speak @name + " wants a cracker" end end class Octopus < Animal def initialize (name = "Oliver") super(name, 8) end end zoo = [Animal.new, Animal.new("Homer", 6), Dog.new, Dog.new("Rover", "Terrier"), Parrot.new, Parrot.new("Fred"), Octopus.new] for k in 0..zoo.length- 1
end