Neither one of them will compile as written, as the "S" in "System" must be capitalized. But given that, they're actually both perfectly fine, as long as they're within a method or initializer block. What compiler errors are you seeing?
The code is Perfectly alright if you use S instead of s in System.out.println(...)
output for the first code is ---------------------------------
Value is 30
----------------------------------
and the output for the 2nd code is ---------------------------------
aa20
----------------------------------
I think here you are getting confused, 2nd output is like aa20 because you are printing d1 then with +d2 you are getting the value of d2. I think for you more explanation is required so i request Mr Ernest Friedman-Hill to explain this topic, because i know this wil b result but dont know the exact answer. So plz explain this.
Primitive types can be printed as is inside System.out.println() without the compiler grumbling. If you are doing any operations with the primitives inside the System.out.println() these will get evaluated first and then the result printed. You don't need to concatenate a string literal before (or after) the primitive in order to get the above results.
Here in this case we are not concatinating the string right? ya i got Your Point but in the previous case, value of d1+d2 is aa20. means it is adding the vaue of d1 with d2. right? means it is adding 'aa' with 20 so the result is aa20. am i right? but when we add supose d1 value is 'a' & d2 value value is 20, the result is not like a20. but it wiil take the ASCII value. So why not here(aa20) it takes the ASCII value, may be the reason is that 'aa' doesnt have any ASCII value. right? is it so.? or any other reason? please explain, coz i'm getting confused here? i know it is very stupid kind of Qn but please explain me why it is behaving like this.?
Thanxs Sheetal
Don't get me started about those stupid light bulbs.