Complete the eager singleton

Report a typo

Complete the given SimpleCounter class as eager (not lazy) singleton. It should contain the following parts:

  • a private no-argument constructor;
  • a private static field instance that holds the created instance;
  • a public static method getInstance without arguments, it returns the same instance of the class;
  • a public integer non-static field counter.

You will not read input or print output in this problem.

If your solution is wrong, you will get a compile-time error or a runtime exception.

Write a program in Java 17
class SimpleCounter {
// write your code here
}
___

Create a free account to access the full topic