Actually, all member variables are defaulted to null for references, false for booleans, and 0 for other primitives, regardless of being final. Since your method doesn't actually change the value of j (it just assigns the value of itself to itself), your answer is 0.
Actually, all member variables are defaulted to null for references, false for booleans, and 0 for other primitives, regardless of being final. Since your method doesn't actually change the value of j (it just assigns the value of itself to itself), your answer is 0.
John.
But i have read somewhere that java does not assign default value to final variable because if it assigs default value then it can not be changed,so it expect us to provide the value.
Well, your program ran, so whoever wrote that was incorrect. If Java didn't assign a default, you'd probably get a random number. I did a test to check all three cases:
I consistently get this result:
So clearly, final variables get assigned defaults.