Results 1 to 2 of 2
Thread: forced casting
- 03-06-2009, 03:18 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
forced casting
Hi I wnat to know the diffrent between the 2 code:
why a' doesnt work and b' does?
a.
{ public class PlusExample
{ public static void main(String[] args)
{
int i = 0;
double d = 1.0;
i = i + d;
System.out.println(i);
}
b.
{
public class PlusExample
{
public static void main(String[] args)
{
int i = 0;
double d = 1.0;
i += d;
System.out.println(i);
}
Thanks
}
- 03-06-2009, 05:49 PM #2
(double posted in advance section as well)
b: i assume the compiler is smart enough to autocast d to int then add to i. but in a: it adds i and d first so you get a double value. then trying to assing an int to a double is an error.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
What does casting mean?
By sev51 in forum New To JavaReplies: 3Last Post: 01-27-2009, 04:31 PM -
casting help
By soc86 in forum New To JavaReplies: 4Last Post: 01-13-2009, 11:07 PM -
Casting an int value into a char
By kurtulas in forum New To JavaReplies: 2Last Post: 02-16-2008, 08:03 PM -
Casting
By leebee in forum New To JavaReplies: 5Last Post: 08-10-2007, 12:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks