Kotlinlearncs.online LogoJava
Return to List

Solve: Book Class

Created By: Justin Maier
/ Version: 2024.9.0

Write a public class Book that has the following instance variables:

  • title: a String
  • author: a String
  • pages: an int representing the number of pages You should supply two constructors: one that takes three arguments to initialize all three fields, and another that only takes two arguments and just initializes the title and author fields.

Additionally, you should supply getter methods getTitle, getAuthor, and getPages that return the respective fields.

You will need to prefix the class and constructors with public. We will talk about what this means next time!

Related Lessons

Stuck? You may find these lessons helpful: