The question: Question 4) A byte can be of what size 1) -128 to 127 2) (-2 power 8 )-1 to 2 power 8 3) -255 to 256 4)depends on the particular implementation of the Java Virtual machine answer: 1) A byte is a signed 8 bit integer.
In my opinion to the correct answer be 1, the question should be "A byte can be of what range?" Do you agree, is it true to say that the size of a byte is implementation dependent, but the range must be unique???
Originally posted by leandro oliveira: ...is it true to say that the size of a byte is implementation dependent, but the range must be unique???
The size of a byte will always be 8 bits - the Java specifications say so. In some other languages (C++, for instance), various compilers might very well use different sizes for data types, but Java doesn't do that. All compilers must compile code so that it can be understood by any JVM. Therefore, a byte will always be 1 byte. However, I agree that the question is worded poorly. The size of a byte will always be 8 bits, the range of a byte is -128 to 127. I hope that helps, Corey