+ 1

Question about variable format

So, I was going through the strings portion of java and ran across a variable like this: "String var;" and underneath it said "var = "string here";". My question is why not simply say "String var = "string";"?

20th Jan 2017, 8:56 AM
Alex Booth
Alex Booth - avatar
3 ответов
+ 3
smart boy. why dont you give it a go in codeplayground. ps check out c++ if you get the chance
20th Jan 2017, 9:09 AM
jay
jay - avatar
+ 2
So I checked in the code playground and they both work, I'm assuming you'd separate the declaration and value when you want to keep things organized a bit more than usual?
20th Jan 2017, 9:16 AM
Alex Booth
Alex Booth - avatar
+ 2
yep. keeping them seperate makes it a little easier to read later on.
20th Jan 2017, 10:40 AM
jay
jay - avatar