Тесты
Язык сайта: Русский
Українська
English
Русский
Тесты по программированию
Вход
Регистрация
Тесты по программированию
Теория
сниппеты
Статьи
Главная
Android
Цены
FAQ
История Cosmo
Правила и условия сервиса
Политика конфиденциальности
Политика в отношении файлов cookie
Обратная Связь
Thread class
:
Язык контента: English
Русский
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; } }
Thread 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(); } }
Thread class
What will be the result of the following program execution? public class MyThread extends Thread { public void run() { System.out.println("I'm Running!"); } public static void main(String[] args) { System.out.println("About to run thread"); new MyThread("Run, Thread, Run!").start(); } }
Thread class
What is the result of the following code execution? public class TestThread extends Thread { public void run() { System.out.println( "Run!" ); } public void begin() { System.out.println( "Begin!" ); } public void execute() { System.out.println( "Execute!" ); } public static void main( String[] args ) { TestThread myTest = new TestThread(); myTest.start(); } }
Thread class
Select the only true option of compilation and running the code. public class MyThread extends Thread { public static void main(String[] args) { new MyThread().start(); } }
Thread class
What happens at compile-time and running this code? class MyThread extends Thread { public void run() { System.out.print("Running "); } public void start() { System.out.print("Starting "); } } public class Q202 { public static void main(String[] args) { MyThread t = new MyThread(); t.start(); } }
Thread class
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"); } }
Thread class
What will be the result of the following code compilation and execution? public class SleepMain { public static void main(String... args) { Thread t = new MyThread(); for (int i = 1; i <= 5; i++) { System.out.print(i + " "); try { t.sleep(1000); } catch (InterruptedException e) { System.out.println("Interrupted in main"); } } } static class MyThread extends Thread { public void run() { for (int i = 1; i <= 5; i++) { System.out.print(i + " "); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Interrupted in myThread"); } } } } }
Thread class
Given the two examples below, what happens if they are compiled and executed? Example №1: public class Main { public static void main(String[] args) { new Thread(){ { this.setDaemon(true); } public void run() { while(true) { System.out.println("Thread is running!"); } } }.start(); } } Example №2: public class Main { public static void main(String[] args) { new Thread() { public void run() { while(true) { System.out.println("Thread is running!"); } } }.start(); } }
Thread class
What will be the output of the following code? import java.util.*; import java.util.concurrent.*; class ExampleThread extends Thread { private static CountDownLatch latch = new CountDownLatch(1); private static Semaphore semaphore = new Semaphore(1, true); private int type; private String[] letters = { "A", "B", "C", "D", "E" }; ExampleThread(int type) { super(); this.type = type; } public void run() { try { if (type == 0) { semaphore.acquire(); latch.countDown(); } else { latch.await(); semaphore.acquire(); } for (int i = 0; i < 5; i++) { if (type == 0) { System.out.print(i); } else { System.out.print(letters[i]); } Thread.sleep(100); } } catch (Exception ex) { System.out.println("Exception 2"); } semaphore.release(); } public static void main(String[] args) { new ExampleThread(1).start(); new ExampleThread(0).start(); } }
Thread class
← Предыдущая
1
2
Следующая →
Зарегистрируйся сейчас
или
Подпишись на будущие тесты