Тесты
Язык сайта: Русский
Українська
English
Русский
Тесты по программированию
Вход
Регистрация
Тесты по программированию
Теория
сниппеты
Статьи
Главная
Android
Цены
FAQ
История Cosmo
Правила и условия сервиса
Политика конфиденциальности
Политика в отношении файлов cookie
Обратная Связь
Thread class
:
Язык контента: English
Русский
What will be the result of compiling and running the following program? class MyRunnable implements Runnable { public void run() { System.out.println("Runnable!"); } } public class MyThread extends Thread { public MyThread() { super(); } public MyThread(Runnable target) { super(target); } public void run() { System.out.println("Thread!"); } public static void main(String[] args) { new MyThread().start(); new MyThread(new MyRunnable()).start(); } }
Thread class
What happens after the compilation and execution of this code? public class S1 implements Runnable { int x = 0, y = 0; int addX() { x++; return x; } int addY() { y++; return y; } public void run() { synchronized (this) { for (int i = 0; i < 10; i++) System.out.print(addX() + " " + addY() + " "); } } public static void main(String args[]) { S1 run = new S1(); Thread t1 = new Thread(run); Thread t2 = new Thread(run); t1.start(); t2.start(); } }
Thread class
What will be the output of the following code: public class Main extends Thread { private int a; public Main() { a = 2; start(); System.out.println(a); } public void run() { a++; } public static void main( String[] args ) { new Main(); } }
Thread class
What will happen while running the following code? public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); try { t.start(); } catch (IOException ioe) { System.out.println("IOException"); } } public void run() throws IOException { File f = new File("file.txt"); FileWriter fw = new FileWriter(f); } }
Thread class
What will be printed out while running the following code: class Synchronized { private Synchronized() {} //1 private static int order = 0xFace; //2 public void saySomething(String name) { System.out.print(name); } public static void main(String[] args) { new Thread() { public void run() { order++; this.yield(); //3 synchObj.saySomething("I am " + order + " "); } }.start(); //4 new Thread() { public void run() { ++order; this.setPriority(MAX_PRIORITY); synchObj.saySomething("I am " + order + " "); } }.start(); //4 } private static Synchronized synchObj = new Synchronized(); //5 }
Thread class
Which is the result of compiling and running the following code: public class MyThread implements Runnable { public void run() { System.out.println("hello"); try { Thread.sleep(Math.round(200 * Math.random())); } catch (InterruptedException e) { } System.out.println("world"); } public static void main(String[] args) { new Thread(new MyThread()).run(); new Thread(new MyThread()).run(); } }
Thread class
What will be the result of compilation and execution of the following code: // file Thread.java 1. package ThreadTest; 2. public class Thread implements Runnable { 3. public void run() { 4. System.out.println("thread"); 5. } 6. } // file Thread2.java 10. package ThreadTest; 11. public class Thread2 implements Runnable { 12. public void run() { 13. System.out.print("thread2"); 14. } 15. public static void main(String[] args) { 16. Thread2 thread = new Thread2(); 17. Thread t1 = new Thread(thread); 18. t1.start(); 19. } 20. } Select all that apply.
Thread class
← Предыдущая
1
2
Следующая →
Зарегистрируйся сейчас
или
Подпишись на будущие тесты