Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int to char casting

 
mailssk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3711
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ira Jain
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic