Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

Inheritance

Rather than starting with a high-level description, I think it'll be best if we jump right into a problem.

To get us started, I've created a basic Java program, which we can access from the given code files. In this program, we declare two Java classes: a Book class and a Poem class. Both the Book and Poem classes store a number of attributes; for example, Book can have a title, an author, a publisher, and a genre. It takes all these attributes as constructor input and provides a single public method; we can use the Print method in our main program to print out information about any books we create.

The Poem method does something very similar. It has a couple of attributes and a Print method, and we set its attributes through its constructor. I've whipped up a really quick main function to utilize the Book and Poem classes. This function creates a new...

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
Banner background image