I am trying to execute the below code:
public class HelloWorld{
public static void main(String []args){
int a=10,b=3,m;
System.out.println("Hello World "+a+" " + b);
}
}
I was expecting a compilation error for not initializing local variable 'm' but the program ran successfully and gave me the output.
Why is it so ? I was thinking in all the cases if the local variable is not initialized the compiler will give an error.
When I try to compile the code given below
public class HelloWorld{
public static void main(String []args){
int a=10,b=3,m;
System.out.println("Hello World "+a+" " + b + " " +m);
}
}
Here I am using the value of 'm' and I am getting error for not initializing local variable.
But why doesn't Java show an error in the first case?