Multiple choice technology programming languages

public class Sample{ public static void main(String[] args){ int i=5; if(i==5) throw new ArithmeticException("i is 5"); System.out.println(i); } } Does the code compiles fine?

  1. True

  2. False

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

The code compiles fine. The ArithmeticException is a checked exception that can be thrown in this context. The main method can throw any exception since it's the entry point. The code would compile but would terminate at runtime with the exception, never reaching the println statement. Option A (True) would be the correct answer if the question asked about compilation.