This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why does this compile? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why does this compile? " Watch "why does this compile? " New topic
Author

why does this compile?

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


how is (f<c) even compiling? arent they of different types?
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
is this because in an arithmetic operation the char will be promoted to float? i think this could be the reason...

please confirm
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
I think char is internally converted to float or int.


Sage of The Monstrous Toad of Mount Myoboku
Chintan B Shah
Ranch Hand

Joined: Sep 23, 2008
Posts: 83
I think "widening" happens here and "if" boolean expression would look something like this
if(9<97)

My 2 cents.

Thanks
Chintan.

SCJA 1.0
Hiruka Sandev
Greenhorn

Joined: Nov 22, 2009
Posts: 11
Internally a char is a 16 bit unsigned integer. So a char can be used in places where a integer literal could be used.
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
First of all char is of integer type.
And secondly i agree with Ankur char will be promoted to float.

Dejan.


SCJP 1.6 in progress ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does this compile?
 
Similar Threads
Which pattern to use?
redefining inherited fuctions, what gets called then ?
instanceof
Ordinal Coparisons Question
polymorphism and casting question logic