I always thought that polymorphism was the ability to implement the same behavior in different ways. An Animal would move (public void move()) but the way a Cat would implement move would be different from the way an Elephant would implement move. But that is not the case, polymorphism is the forcing the Cat class and Elephant class to implement move() method in their own way by having them implement an IAnimal interface with a public void move(); method. It is inheritance and method implementation that we see here. Method overriding does not mean the classes are exhibiting polymorphic behavior. See the Wiki for more details http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming
No comments:
Post a Comment