Junior — Middle
What methods can be used to declare an integer variable that can accept null value?
sobes.tech AI
Answer from AI
In Java, a variable of type int cannot accept the value null because it is a primitive type. To allow an integer type variable to accept null, you need to use the wrapper class Integer.
Example declaration:
Integer number = null; // allows null
int primitiveNumber; // does not allow null
Therefore, for a variable that allows null, use the wrapper class Integer instead of the primitive int.