I'm having some confusion with the reasoning behind what seems to me to be an inconsistency.
For example
public class Test
{
static int a;
public static void main(String[] args)
{
System.out.println(a);
}
}
So that will print out 0, as expected. But say we had this instead,
public class Test
{
public static void main(String[] args)
{
int a;
System.out.println(a);
}
}
This won't compile for me, complaining that a hasn't been initialized. I was expecting it to print out 0...
Which leads me to some questions:
1) Why don't function scoped variables have default values?
2) Could the static keyword be the reason? And why?