014-003-007

super() Call with Multiple Arguments

Medium

Problem Description

super() Call with Multiple Arguments

In this problem, you will create a program that builds an inheritance relationship between Product and Book classes, calls the parent constructor using super(name, price) with multiple arguments, and displays the result to standard output.

Learning Objective: Understand how to call parent class constructor with multiple parameters using super()

Overview

Define Product as the parent class and extend it in Book. Inside Book's constructor, call super(name, price) to initialize the parent class fields, then initialize the author field specific to Book.

Specifications

  • Define a constructor in Product class that takes String name and int price
  • Book class extends Product and has an additional String author field
  • Book constructor takes name, price, author and passes name, price to the parent via super(name, price)
  • In Main class, read values from standard input, create a Book instance, and output its information

Input Format

{name}
{price}
{author}

Output Format

Book: {name}, Price: {price}, Author: {author}

Input/Output Example

Input:
Java Guide
3000
Yamada

Output:
Book: Java Guide, Price: 3000, Author: Yamada

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