Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java Programming for Beginners

You're reading from   Java Programming for Beginners Learn the fundamentals of programming with Java

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781788296298
Length 318 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
SkillSprints Inc., Mark Lassoff SkillSprints Inc., Mark Lassoff
Author Profile Icon SkillSprints Inc., Mark Lassoff
SkillSprints Inc., Mark Lassoff
Arrow right icon
View More author details
Toc

Abstract

In this section, we'll take a quick look at an important idea that relates to inheritance in Java. To wrap our heads around what we're going to talk about, I think it's best if we start an existing project in the system. So let's take a look at the code we have in the code files.

So far, we've done the following:

  • The main method of our program creates a list of objects. These objects are either of the type Book or Poem, but we've placed them in a list of Literature objects, leading us to believe that the Book and Poem classes must inherit from or extend the Literature class.
  • Once we've built this array, we simply iterate through it using a for loop and call the Print method of this for loop on each object.
  • At this point, we're dealing with objects as Literature objects, not the Books or Poems that they are at the lowest level....
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime