fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Sample
  9. {
  10. public static void main(String[] args)
  11. {
  12.  
  13. Employee e1 = new Employee(1, "A");
  14. e1.count++;
  15. Employee e2 = new Employee(1, "A");
  16. e2.count++;
  17.  
  18. System.out.println(Employee.count); }
  19. }
  20. class Employee
  21. {
  22. int id;
  23. String name;
  24. static int count = 0;
  25.  
  26. Employee(int i, String s)
  27. {
  28. id= i;
  29. name = s;
  30. }
  31. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
2