Java
Which keyw ...
Мова сайту: Українська
Українська
English
Русский
Тести з програмування
Вхід
Реєстрація
Тести з програмування
Теорія
Сніпети
Статті
Головна
Android
Ціни
FAQ
Історія Cosmo
Правила та умови сервісу
Політика конфіденційності
Політика щодо файлів cookie
Зворотній Зв’язок
Which keyword is used to show that the method can not work with more than one thread at a time?
synchronized
sealed
protected
locked
volatile
Explanation
Get an explanation when it's available:
Subscribe
multithreading
synchronized
1
(1)
Подобається
Ввійдіть
щоб вподобати
Комментувати
Ввійдіть
щоб прокоментувати
Поширити
Tweet
Пов'язані матеріали
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"); } }
What is the result of the following code execution? public class Starter extends Thread { private int x = 2; public static void main(String[] args) throws Exception { new Starter().makeItSo(); } public Starter() { x = 5; start(); } public void makeItSo() throws Exception { join(); x = x - 1; System.out.println(x); } public void run() { x *= 2; } }
Which of the following methods are defined in the Object class?
What will happen after the following code is compiled and executed? public class Main implements Runnable { public void run() { System.out.println("Hello"); Thread.currentThread().sleep(100); } public static void main(String... args) throws InterruptedException { new Thread(new Main()).start(); } }
What is the result of the code? import java.util.*; public class TestIterator{ public static void main(String[] args){ final List synchList = Collections.synchronizedList(new ArrayList()); fillList(synchList, 10); Thread anotherThread = new Thread(){ public void run(){ try{ Thread.sleep(300); }catch (InterruptedException e){ System.out.println("anotherThread interrupted"); return; } synchList.remove(1); synchList.remove(7); } }; anotherThread.start(); Iterator iterator = synchList.iterator(); while(iterator.hasNext()){ System.out.print(iterator.next()); try{ Thread.sleep(100); } catch (InterruptedException e) { System.out.println("Main thread interrupted"); return; } } } static void fillList(List list, int n){ for(int i = 1; i <= n; i++) list.add(i); } }
Тести з
J
ava
Приєднуйся і вивчай Java
або
Дізнайся більше про
Тести з Java онлайн
Слідкуй за CodeGalaxy
Мобільний додаток Beta
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
What will be printed out as a result of the following code execution / compilation? class A { public A() { System.out.print("A"); } } class B { public B() { System.out.print("B"); } } class C { public C() { System.out.print("C"); } } public class D extends C { private A objA = new A(); private static B objB = new B(); public D() { System.out.print("D"); } public static void main(String[] args){ new D(); } }
What will be printed out as a result of the following code execution / compilation? public class Test { private String name; Test(String name) { this.name = name; } public void test(final Test test) { test = new Test("three"); } public String toString() { return name; } public static void main(String[] args) { Test t1 = new Test("one"); Test t2 = new Test("two"); t1.test(t2); System.out.println(t2); } }
What will be printed out as a result of the following code execution / compilation? public class Test { static void m(int ... a) { System.out.println("1"); } static void m(Integer ... a) { System.out.println("2"); } public static void main(String[] args) { m(1, 2); } }
What will be printed out as a result of the following code execution / compilation? public class Test { public static void main(String[] args) { ElectricInverter inverter = new ElectricInverter(); int AC = 220; System.out.println(inverter.invert(AC)); } } class ElectricInverter { public static final int AC = ~220; public static final int DC = -110; public static final int GROUND = 0; int invert(int type) { if (type == AC) { return DC; } else if (type == DC) { return AC; } return GROUND; } }
int i = Integer.MAX_VALUE + 10; What is the result of the given line execution?
What happens after the following code is compiled and run: 01: interface TheInterface { 02: void print(); 03: } 04: 05: class TheClass implements TheInterface { 06: public void print() { 07: System.out.println("TheClass"); 08: } 09: } 10: 11: public class ClassConversion { 12: public static void main(String[] args) { 13: TheClass c = new TheClass(); 14: TheInterface i = c; 15: i.print(); 16: } 17: }
Зареєструйся Зараз
або
Підпишись на майбутні тести
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати