A Ka wrote:Can somebody please explain me the difference below?
doesn't compile. Java statements, that are not declarations, need to be in a code block -- either initializer, constructor, or method. And please don't run code that doesn't compile -- you won't know what you are getting.
won't compile because the separate "n=11" statement is an assignment statement, and you generally can't have an assignment statement outside of any methods. In the other version, the " = 11 " thing is part of the declaration of the "n" variable and that's okay to do.