Hello all,
As Iam in starting stage of
JAVA ,I got this doubt.Actually tried to point out the reason by myself ,but could not,so taking help from you all.
when Iam trying to assign a double variable(which occupies 64 bits) to a var.of type float(which occupies 32 bits) ,compiler is showing error,but when I cast it,it is not showing any error.But,when Iam trying to assign a long,var.(which occupies 64 bits) to float(which occupies 32 bits) with out casting its not giving any error message.May I know the reason behind this?
I wrote a program like this.
public class castTest
{
public static void main(
String arg[])
{
float f=10.3F;
long l=32767;
double d=-2147483648;
System.out.println("before Casting");
System.out.println("float f is "+f);
System.out.println("long l is"+l);
System.out.println("double d is "+d);
f=(float)d;
System.out.println("after assigning double value d to f,new f is "+f);
f=l;
System.out.println("after assigning long value l to f,new f is "+f);
}
}