October 2017
Beginner
318 pages
7h 26m
English
There's no easily accessible data structure that will happily store both books and poems. We'd probably have to use two data structures or break strong typing, which is the whole point of Java:
Book[] books = new Book[5];
However, with our new implementation, where Book and Poem both inherit from Literature, we can store them in the same data structure. This is because inheritance is an is-a relationship, meaning that we can, once we've inherited from something, make claims such as book is literature and poem is a literature too. If that's true, then an array of Literature objects should be able to store both Book and Poem within it. Let's go through the following steps to illustrate this:
Read now
Unlock full access