012-001-005

Static Variable: Counter

Medium

Problem Description

Static Variable: Counter

Learning Objective: Understand that static variables are shared across the class

Overview

Static variables are shared by all objects. Create a program that counts the number of objects created.

Specifications

  • Define static variable count in Counter class
  • Increment count in constructor
  • Display count after creating 3 objects

Output Format

Total count: 3

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 9 free executions remaining