Java Reference
In-Depth Information
Review Questions
1.
What is the result of the following code?
3. byte twelve = -12;
4. Byte b1 = new Byte(twelve);
5. Byte b2 = new Byte(twelve);
6. if(b1.byteValue() == b2) {
7. System.out.println(“equal”);
8. } else {
9. System.out.println(“not equal”);
10. }
A.
Line 6 generates a compiler error.
B.
An exception is thrown on line 6.
C.
equal
D.
not equal
2.
What is the result of the following program?
1. public class Unboxer {
2. private Integer x;
3.
4. public boolean compare(int y) {
5. return x == y;
6. }
7.
8. public static void main(String [] args) {
9. Unboxer u = new Unboxer();
10. if(u.compare(21)) {
11. System.out.println(”true”);
12. } else {
13. System.out.println(”false”);
14. }
15. }
16. }
A.
true
B.
false
C.
Line 5 does not compile.
D.
Line 5 throws an exception.
E.
Line 10 does not compile.
Search WWH ::
Custom Search