Sail E0 Webinar
Question

Which two can be used to create a new Thread?

     1. Extend java.lang.Thread and override the run() method.

     2. Extend java.lang.Runnable and override the start() method.

     3. Implement java.lang.Thread and implement the run() method.

     4. Implement java.lang.Runnable and implement the run() method.

     5. Implement java.lang.Thread and implement the start() method.


Options:
A .  1 and 2
B .  2 and 3
C .  1 and 4
D .  3 and 4
Answer: Option C

There are two ways of creating a thread; extend (sub-class) the Thread class and implement the Runnable interface. For both of these ways you must implement (override and not overload) 

the public void run() method.

(1) is correct - Extending the Thread class and overriding its run method is a valid procedure.

(4) is correct - You must implement interfaces, and runnable is an interface and you must also

 include the run method.

(2) is wrong - Runnable is an interface which implements not Extends. Gives the error: (No 

interface expected here)

(3) is wrong - You cannot implement java.lang.Thread (This is a Class). (Implements Thread, 

gives the error: Interface expected). Implements expects an interface.

(5) is wrong - You cannot implement java.lang.Thread (This is a class). You Extend classes, 

and Implement interfaces. (Implements Thread, gives the error: Interface expected)



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers