007-001-013
Class Creation: Constructor
Medium
Problem Description
Class Creation: Constructor
Learning Objective: Understand how to initialize fields using constructors
Overview
Create a class that initializes fields using a constructor.
Specifications
- Create a
Productclass - Define a String field
name - Define an int field
price - Initialize both fields in constructor
- Create
getInfo()method that returns "name: price yen" format string - Create instance in Main and output the result
Output Format
Apple: 150 yen
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
