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 )

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes