• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Char to Short

 
Roja Rani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In Java rules round up game, the following question is given.

Can you automatically/implicitly convert char to short?

I have answered True for this because, if the char is final variable and is within the range of short, it can be assigned to short implicitly.

But the answer given is False. How to answer this question?
 
Santana Iyer
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you automatically/implicitly convert char to short?

I have answered True for this because, if the char is final variable and is within the range of short, it can be assigned to short implicitly.


What you said is right but is it always going to be the case NO,
so when asked such question ask yourself is it always going to be true ANSWER IS NO.

Read question carefully if it is char is final variable and is in range of short can it be assigned to short implicitly now you can say YES.

short range is -32k to 32k while char is only positive 0 to 65k
also keep that in mind.
 
Roja Rani
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for the clarification.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic