File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes int to char casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int to char casting" Watch "int to char casting" New topic
Author

int to char casting

mailssk
Greenhorn

Joined: Oct 10, 2000
Posts: 6

This code has no Compilation and Runtime error. How does the code work? There is no implicit casting of int to char
Can anyone explain?
class Main{
public static void main(String argv[])
{
char i= 10;
int j='h';

}
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3335
    
    8
This may help you...
http://www.enthuware.com/jqplus/FAJQuestions.html
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
Hi ,
It does not display an error in case of char i=10 because 10 is within the valid range of values for a char literal.If we try to store a value which is above its range like 1234567890 it will give an error.
In case ,of the second statement int i='h',it is a case of widening conversion . An integer literal can hold short,char and byte literals without any conversion.
Hope the above will help u.
Ira
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int to char casting