What will be the output of the following Java program? [code] class Output { public static void main(String args[])

KellyPoima

New member
What will be the output of the following Java program?
Code:
    class Output 
    {
        public static void main(String args[]) 
        {
            Integer i = new Integer(257);  
            byte x = i.byteValue();
            System.out.print(x);
        }
    }
A. 0
B. 1
C. 256
D. 257
 
Answer: b
Explanation: 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:
Code:
$ javac Output.java
$ java Output
1
 

Tìm kiếm

Back
Top