012-001-004

Static Variable: Instance Counter

Medium

Problem Description

static variable: Instance Counter

In this problem, you will create a program that defines a static variable count in a Counter class, increments it each time a new instance is created, and displays the running total of instances created to standard output.

Learning Objective: Understand that static variables are shared across all instances

Use static variable in Counter class to count instance creations.

Input

Line 1: Number of instances to create (1-5)

Output

On each creation: Created instance #[number]
Finally: Total instances: [total]

Example

Input:

3

Output:

Created instance #1
Created instance #2
Created instance #3
Total instances: 3

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