I have been trying to find out the Why am I getting a ' '
when I print a char variable which was initialized with the default value of '\u0000'
?
Also I know that float and double has a default value of "0.0f" and "0.0d", but here when I print their default values the suffix "f" and "d" are not printed. So why are these suffixes not printed with the values?
Here's the code:
class Check{
char c;
float f;
double d;
public static void main(String a[]) {
Check obj = new Check();
System.out.println("Default value of char : " + obj.c);
System.out.println("Default value of float : " + obj.f);
System.out.println("Default value of double: " + obj.d);
}
}
In the code for default value of char is printed as ' '. For float it is "0.0" and for double is "0.0". In short my question is: Why am I getting a ' ' instead of '\u0000' or null (or something like this) for char? Why the suffix present in the default values of float and double are not printed? (like "0.0f" and "0.0d")
Note: There are other questions like: Primitives/Objects Declaration, default initialization values and what's the default value of char?, but unlike my question these questions discuss only about their default values not about printing them.