Which of the following lines will not compile ?? Choose Two.
1: public class Question1 {2: public Question1() {3: }4: public static void main(){5: Thread t1 = new Thread(); // Line 16: Thread t2 = new Thread(new MyClass());//Line 27: Thread t3 = new Thread(new MyClass(),"Thread3");//Line 38: Thread t4 = new Thread("Thread4");//Line 49: Thread t5 = new Thread("Thread5",5);//Line 510: Thread t6 = new Thread ("Thread6", new MyClass());//Line 611: }12: }13: class MyClass implements Runnable{14: public void run(){}15: }
Options :
a. Line 1
b. Line 2
c. Line 3
d. Line 4
e. Line 5
f. Line 6
Answer : e & f. ie Line 5 and Line 6.
This question tries to find your understanding of Thread constructor.
Line 5 is does not compile because Thread constructor don’t have a method to accept Thread priority. Similarly Line 6 does not compile because there is no such constructor to accept name and runnable interface.
JAVA API for reference.
Thread()
Allocates a new Thread
object.
Thread(Runnable target)
Allocates a new Thread
object.
Thread(Runnable target, String name)
Allocates a new Thread
object.
No comments:
Post a Comment