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
Productclass that takesString nameandint price Bookclass extendsProductand has an additionalString authorfieldBookconstructor takesname, price, authorand passesname, priceto the parent viasuper(name, price)- In
Mainclass, read values from standard input, create aBookinstance, 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