🎴 Flashcard Mode

C#, Perl, and Java Programming Fundamentals

Card1 / 20
Mastered0
Review0
QuestionClick to flip

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?

AnswerClick to flip back
A
False
💡 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.

Change Mode