Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Virtusa Written Test Qs.(JAVA Programming) :: Basic Concepts - Discussion

54 / 119

What will happen when you try to compile and run this code?

public class TGo implements Runnable{
 public static void main(String argv[]){
         TGo tg = new TGo();
         Thread t = new Thread(tg);
        public void run() {
         while(true) {
                        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

Answer: Option (Login/Signup)

Show Explanation

We will get a compile-time error in line no. 9, saying unreported exception InterruptedException; must be caught or declared to be thrown.

The sleep() method is responsible for generating the exception, and hence should be declared under try-catch block.

Hence, correct option is D.

Asked In :: Virtusa

Post Your Answer Here:     

Rate This: +0 -0

Report Error

Please Login First Click Here