Skip to content

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); } }

  1. A.The program will cause an runtime exception because the variable 'i' was not initialized
  2. B.The program will cause an compile error because the object 't' was not initialized
  3. C.0
  4. 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.