Page 1 of 1

About Question enthuware.ocajp.i.v8.2.891 :

Posted: Wed Feb 08, 2017 11:55 am
by jamesmccreary
From reading the Oracle docs regarding primitive default initialization, local variables (method variables) are not given a default value. Is that why:

for(int k; k<0; k++)

is incorrect? Is a for loop considered a method?

Re: About Question enthuware.ocajp.i.v8.2.891 :

Posted: Wed Feb 08, 2017 8:22 pm
by admin
No, for loop is not considered a method. But the variable defined in a for loop is a local variable with scope limited to just the for loop body. So it is not given a default value.

Re: About Question enthuware.ocajp.i.v8.2.891 :

Posted: Thu Feb 09, 2017 12:37 pm
by jamesmccreary
Thank you for the clarification!