🎴 Flashcard Mode
Java Programming and IT Security Basics
Card1 / 17
Mastered0
Review0
QuestionClick to flip
What is the output of the following program? class example { public static void main(String args[]) { int j; do { j++; } while(j < 0); System.out.println(j); } }
AnswerClick to flip back
A
The program does not compile as j is not initialized
💡 Explanation:
Local variable 'j' is used without being initialized - in Java, local variables must be explicitly initialized before use. The 'j++' operation in the do-while tries to increment an uninitialized variable, causing a compile-time error. This is different from instance variables which get default values.