012-001-010

Basic Static Variables

Easy

Problem Description

Basic static Variables

In this problem, you will create a program that defines a static variable in a Counter class, creates 3 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.

Specifications

  • Define static int count = 0 in Counter class
  • Increment count in constructor
  • Create 3 instances and output final count

Output Format

Total instances created: 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