August 8th, 2013, 06:24 AM
If I do this, will I get any NPEs?
I have four variables which are x, y, p, and z.
y= 1, z = 2 but I do not assign any numbers to x. If I do
p = x + y + z, will I get a NPE?
Last edited by Tawijakarta; August 8th, 2013 at 07:14 AM.
August 8th, 2013, 08:32 AM
You don't get NPE with primitive variables. You only get NPEs when working with object references (pointers).
August 8th, 2013, 08:56 AM
As Norm said, you won't get an NPE, but if the x is a local variable, the code won't even compile. You have to explicitly initialize local variables before you use them in an expression that assumes they have a value.
Originally Posted by Tawijakarta
August 9th, 2013, 12:30 AM
However, if by some way it does not give you an error in compiling.
The value defaults to 0.