007-003-012

Creating Multiple Instances

Hard

Problem Description

Creating Multiple Instances

In this problem, you will create a program that instantiates two independent Product objects from the same class, assigns values to each object's name and price fields, and displays the result to standard output.

Learning Objective: Understand creating multiple independent instances from the same class

Overview

Create multiple instances from the same class and verify each holds independent data.

Specifications

  • Product class has name (String) and price (int) fields
  • Create two Product instances
  • First: name="Apple", price=100
  • Second: name="Orange", price=150
  • Output information for both

Output Format

Product 1: Apple, 100
Product 2: Orange, 150

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