011-003-004

Constructor: Calling Another Constructor with this

Medium

Problem Description

constructor: Calling Another constructor with this

In this problem, you will create a program that implements a Product class with multiple constructors chained via this() based on the constructor type read from standard input, and displays the product name and price to standard output.

Learning Objective: Understand calling another constructor in same class using this()

Implement multiple constructors in Product class and chain them with this().

Input

Line 1: Constructor type (default / name / full)
Default: No additional input
Name: Line 2 is product name
Full: Line 2 is name, Line 3 is price

Output

Product: [name], Price: [price]

Example

Input:

default
```java
Output:
```java
Product: Unknown, Price: 0

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