007-001-008
Creating Classes: Product Class
Medium
Problem Description
Creating Classes: Product class
In this problem, you will define a Product class with fields (member variables) for managing product information.
Learning Objective: Create classes and define fields (member variables)
Create a class to represent a product. Learn class definition and how to use fields.
Specifications
- Create a
Productclass - Fields:
String name(product name),int price(price) - Fields must be directly accessible from an instance
How Testing Works
The system will create instances of your Product class, assign various values to the fields, and verify the behavior.
Example Output
Your class will be tested with code like:
Product p = new Product();
p.name = "Laptop";
p.price = 89800;
System.out.println("Name: " + p.name);
System.out.println("Price: " + p.price);
Output:
Name: Laptop
Price: 89800
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