JAVA Programming :: Threads - Discussion
7 / 6
public class TGo implements Runnable{
public static void main(String argv[]){
TGo tg = new TGo();
Thread t = new Thread(tg);
t.start();
}
public void run() {
while(true) {
Thread.currentThread().sleep(1000);
System.out.println("looping while");
}
}
}
public class TGo implements Runnable{
public static void main(String argv[]){
TGo tg = new TGo();
Thread t = new Thread(tg);
t.start();
}
public void run() {
while(true) {
Thread.currentThread().sleep(1000);
System.out.println("looping while");
}
}
}
ACompilation and no output
BCompilation and repeated output of "looping while"
CCompilation and single output of "looping while"
DCompile time error
Show Explanation
When the run() method executes,
Our thread first waits for a time unit of 1000 ms after which it prints looping while, and this goes on repeatedly.
Hence, the code compiles fine and we get repeated output of "looping while".
Asked In ::
Thread TGo is created by implementing the Runnable interface.
When the run() method executes,
Our thread first waits for a time unit of 1000 ms after which it prints looping while, and this goes on repeatedly.
Hence, the code compiles fine and we get repeated output of "looping while".
Read Full Answer
Report Error
Please Login First Click Here