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
multithreading
:
Content language: 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; } }
multithreading
Which of the following methods are defined in the Object class?
multithreading
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(); } }
multithreading
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); } }
multithreading
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(); } }
multithreading
What will be the result of compiling the following code: public class ThreadTest { public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(new TestThread()); System.out.println("Hello, it's a main thread"); thread.start(); thread.join(); System.out.println("Good bye"); } } class TestThread implements Runnable { @Override public void run() { System.out.println("Hello, it's a simple thread"); } public void join() { System.out.println("Hello, it's a method join()"); } }
multithreading
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(); } }
multithreading
Which keyword is used to show that the method can not work with more than one thread at a time?
multithreading
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"); } }
multithreading
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"); } } } } }
multithreading
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes