fork download
  1. public class MainClass{
  2.  
  3. public static void main(String[] args) {
  4. PrimaryThread thread1 = new PrimaryThread();
  5. PrimaryThread thread2 = new PrimaryThread();
  6. thread1.start();
  7. thread2.start();
  8. }
  9. }
  10.  
  11. class PrimaryThread extends Thread{
  12.  
  13. private int counter;
  14.  
  15. public PrimaryThread(){
  16. counter = 0;
  17. }
  18.  
  19. synchronized public void run(){
  20. for(int i = 0; i < 50; i++){
  21. System.out.println(++counter);
  22. }
  23.  
  24. }
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class MainClass is public, should be declared in a file named MainClass.java
public class MainClass{
       ^
1 error
stdout
Standard output is empty