Multiple choice technology programming languages

Given: 1. public class TestOne { 2. public static void main (String[] args) throws Exception { 3. Thread.sleep(3000); 4. System.out.println(”sleep”); 5. } 6. } What is the result?

  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “sleep”.

  4. The code executes normally, but nothing is printed.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Thread.sleep() throws InterruptedException, a checked exception. Since main() declares 'throws Exception', it properly handles this. The code compiles, sleeps for 3 seconds, then prints 'sleep' normally.