-
Book Overview & Buying
-
Table Of Contents
Android Programming for Beginners - Fourth Edition
By :
We already know from the start of Chapter 18 that polymorphism means different forms. But what does it mean to us?
Boiled down to its simplest, it means the following:
Also, we can write code for the super-class and rely on the fact that no matter how many times it is sub-classed, within certain parameters, the code will still work. Let's discuss an example.
Supposing that we want to use polymorphism to help write a zoo management app. We will probably want to have a function, such as feed. Let's also say we have Lion, Tiger, and Camel classes that all inherit from a parent class called Animal. We will probably also want to pass a reference to the animal to be fed to the feed function. This might seem like we need to write a feed function for each Animal subclass.
As a reminder from the end of Chapter 18, when...