Question
class Output {
public static void main(String args[]) {
Integer i = new Integer(257);
byte x = i.byteValue();
System.out.print(x);
}
}
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);
}
}
Answer: Option B
Was this answer helpful ?
i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range of byte is
256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.
Output:
$ javac Output.java
$ java Output
1
Was this answer helpful ?
Submit Solution