Originally posted by jwiscou.chen: Hello everyone I have some doubt follow can anyone suggest why? 1. byte a=0xFF //compile error byte b=0xFFF //compile error byte c=0xFFFFFFFF //but here compile succeed why?
0xFF = 255 0xFFF = 4095 0xFFFFFFFF = -1
and the byte can hold values from -128 to 127. Hence first two statements throw errors, while last one getting compiled.
Here a is char and 8 is an int. When you perform arithmatic operation between char and int, the result will be int. Hence it is throwing error - beucase char cann't hold int value. [ September 16, 2006: Message edited by: Chetan Parekh ]
There are two pieces of knowledge that are required to answer the question: 1) the range of the primitive types 2) what a constant expression is Once you know these, you can reason easily for each of your cases.
Tony Morris Java Q&A (FAQ, Trivia)
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop