Better code:
And the
Cow class should override the feed() method to do whatever addHay() was going to do in the original code; the Bird class should override the feed() method to do whatever addSeed() was going to do; and so forth.
Not only is this much simpler than the original version, it automatically supports feeding of Cockroach and Capybara and Camel and any other subclass of Animal you might choose to create. The original code ignores the existence of
polymorphism, which is one of the foundational features of object-oriented programming whereas this code uses polymorphism and method overriding the way they were meant to be used. Code which ignores the right way to do things and instead uses ugly workarounds which don't even work properly can only be considered bad.