[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

JAVA Programming :: Basic Concepts - Discussion

Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion

54 / 64

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);
         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

Answer: Option (Login/Signup)

Show Explanation

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:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here