Hi, In line 2, k is redeclared. I dont think we can shadow a local variable by another local variable. So, it should give a compilation error. Shadowing happens only when a local variable is declared with same name as an instance variable.
There should be a compilation error in line 3 also because "int" before j is not allowed.
Yes, well, the error pretty much tells you what you need to know: you can't do that. And you've already found alternate ways to do the same thing you were trying to do. They don't want you to repeat the "int" part of the declaration because if you did that, you could also write a loop that declares an int and a String, for example. Not that this is inherently wrong, necessarily, but the language designers made a conscious choice to limit how much complexity you are allowed to put into a single for statement. They allow more than one variable to be initialized, only if the variables are of the same type - and in that case, they can share the type declaration (the word "int" in this case); you don't have to repeat it.
"I'm not back." - Bill Harding, Twister
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop