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.
Explanation
Compilation error in 17, because that line attempts to create an instance of ThreadTest.Thread (not java.lang.Thread) which does not have any declared constructors with parameters. ThreadTest.Thread has only a default constructor with no parameters, because constructors are not members, therefore they are not inherited. ( http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html )

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты