ProghubPH
Вопрос из теста Java основы
Java / junior

Что будет выведено на экран?

 один вариант
public class TestMethods{ 
    public static void main(String[] args){ 
        TestMethods test = new TestMethods(); 
        Thread anotherThread = new Thread("Thread#2"){ 
            public void run(){ 
                staticMethod(); 
            } 
        }; 
        anotherThread.start(); 
        test.instanceMethod(); 
    } 
     
    public static synchronized void staticMethod(){ 
        System.out.println("Running static method"); 
        try{ 
            Thread.sleep(1000); 
        } catch (InterruptedException e){ 
            System.out.println(Thread.currentThread().getName() + " interrupted!"); 
        } 
        System.out.println("Exiting static method"); 
    } 
     
    public synchronized void instanceMethod(){ 
        System.out.println("Running instance method"); 
        try{ 
            Thread.sleep(1000); 
        } catch (InterruptedException e){ 
            System.out.println(Thread.currentThread().getName() + " interrupted!"); 
        } 
        System.out.println("Exiting instance method"); 
    } 
} 
Running static method Exiting static method Running instance method Exiting instance method
Running instance method Exiting instance method Running static method Exiting static method
Running static method Running instance method Exiting static method Exiting instance method
Невозможно предсказать.