Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
synchronized
:
Content language: English
Русский
Which keyword is used to show that the method can not work with more than one thread at a time?
synchronized
What will be displayed? 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"); } }
synchronized
← Prev
1
Next →
Sign Up Now
or
Subscribe for future quizzes