007-003-012
Creating Multiple Instances
Hard
Problem Description
Creating Multiple Instances
In this problem, you will design a Product class that can be used to create multiple independent instances. Implement name (String) and price (int) fields, and a getInfo() method that returns the product information as a formatted string.
Learning Objective: Design a class that supports creating multiple independent instances
Specifications
- Create a
Productclass - Has a
namefield (String) - Has a
pricefield (int) getInfo()method returns a string in the format"name, price"
Usage Example
Product p = new Product();
p.name = "Apple";
p.price = 100;
System.out.println(p.getInfo()); // Apple, 100
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