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
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
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
