Multiple Interfaces in One Class - Flyable and Swimable
Using the Flyable example as a starting point, we can add a second interface, Swimmable, with the following code:
The Duck object can Implement both flying and swimming:
A Fish class can implement Swimmable, too:
Now, we can see that the Duck object can be passed to a Sub as a Flyable on one hand, and a Swimmable on the other:
The output of this code is:
Flying With Wings!
Flying With Jet Engines!
Floating on the water
Swimming under the water