Computer Applications
What is the output of this program?
class Output {
public static void main(String args[])
{
Integer i = new Integer(257);
byte x = i.byteValue();
System.out.print(x);
}
}
- 0
- 1
- 256
- 257
Java Library Classes
21 Likes
Answer
1
Reason — The byte datatype stores values in the range 0..255 and if we try to convert an integer value bigger than 255 using byteValue( ) method then, the byte data type will convert the value into the range of 0…255 in cyclic fashion. Thus, integer value 256 and 257 will be converted to byte value 0 and 1 respectively.
Answered By
10 Likes
Related Questions
Write the return data type of the following functions :
- startsWith( )
- random( )
Which of the following statements are true ?
- The Integer class has a String- and an int-constructor.
- The Integer has a floatValue( ) method.
- The wrapper classes are contained in the java.lang.Math package.
- The Double class has constructors for type double and float.
What is the output of this program ?
class Output { public static void main(String args[]) { Integer i = new Integer(514); float x = i.floatValue(); System.out.print(x); } }- 0
- 1
- 257
- 514.0
What are wrapper classes?