012-001-010
Basic Static Variables
Easy
Problem Description
Basic static Variables
In this problem, you will create a program that reads an integer n from standard input, defines a static variable in a Counter class, creates n instances to increment a shared counter, and displays the final count to standard output.
Learning Objective: Understand static field characteristics and class-wide sharing
Overview
Implement a counter shared by all instances using a static variable.
Input
- Line 1: Number of instances to create n (1 ≤ n ≤ 100)
Specifications
- Define static int count = 0 in Counter class
- Increment count in constructor
- Create n instances and output final count
Output Format
Total instances created: {n}
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