You can't directly assign null value to any int, float or long datatype variable. To assigning null value you need to declare a special type of variable that is called nullable type. This type of variable is declared with ? symbol.
float? num1 = null;
long? num2 = null;
int? num3 = 250;
Remember you need to assign always the defaul value to nullable type variable as you can't declare it as
For primitive types,we have fixed memory size i.e for int we have 4 bytes and char we have 2 bytes. And null is used only for objects because there memory size is not fixed.
So by default we have,
int a=0;
and not
int a=null;
Same with other primitive types and hence null is only used for objects and not for primitive types.
Suraj KumarPosted Dec 26, 2017, 11:58 AM
Amit KumarPosted Dec 26, 2017, 9:49 AM
Reshwanth SPosted Dec 26, 2017, 8:21 AM
Mohana RPosted Dec 26, 2017, 8:15 AM
Reshwanth SPosted Dec 26, 2017, 7:56 AM