What is the output of this Java program? class Test{ int i=1; } public class main{ public static void main(String args[]){ Test t; System.out.println(t.i); } }
- A.The program will cause an runtime exception because the variable 'i' was not initialized
- B.The program will cause an compile error because the object 't' was not initialized
- C.0
- D.A garbage value
Show answer
Answer: B. The program will cause an compile error because the object 't' was not initialized
In Java, local variables must be explicitly initialized before use; otherwise, a compile-time error occurs.