how int arr[] gets null and how main method a[] gets error
public class Main
{
int arr[];
public static void main(String[] args)
{
int a[];
Main m=new Main();
System.out.println("Main class array"+m.arr); //null
System.out.println("Main method array"+a); //error
}
}
m.arrso, being an instance member, it gets a default value ofnull, and you never initializeaso, being a local variable, it's a compile-time error.arrin your example, are initialized tonullby default. But local variables, which are variables defined inside a method, such asa, are not initialized at all by default. You must initialize them explicitly, otherwise the compiler will complain that you're trying to use an uninitialized variable.