014-008-004

Object Class Inheritance: Overriding toString

Medium

Problem Description

Object class inheritance: Overriding toString

In this problem, you will create a program that defines a Book class, overrides the toString() method, and displays book information in a specified format to standard output.

Learning Objective: Understand that all classes inherit from Object and learn how to override the toString method

Overview

Create a Book class and override the toString method to return book information in a specific format.

Specifications

  • Book class: title (String), author (String) fields
  • constructor: receives title, author and initializes them
  • override toString(): returns "Book[title=xxx, author=xxx]" format

Input

Book title and author name are provided

Output Format

Book[title=Java Programming, author=Smith]

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up