float variables intialization java
The following code snippet gave me compiler error at Line 1.
public abstract class xyz
{
float Gamma = 20.0; //Line 1
public class Alpha
{
void Beta()
{
System.out.println("this is atest");
}
}
}
abc0.java:5: error: possible loss of precision
float density = 20.0;
^
required: float
found: double
2 errors
As per my understanding, float is used for decimal variables.
Am I missing something obvious or should I have to always use casting for
decimal variables initialization ?
EDIT : I know 'f' can be used at the end for float variables but is it
MANDATORY ?.
No comments:
Post a Comment