Analyze the following code.

```
public class Test {
public static void main(String[] args) {
java.util.Date x = new java.util.Date();
java.util.Date y = x.clone();
System.out.println(x = y);
}
}
```
a. A java.util.Date object is not cloneable.
b. x = y in System.out.println(x = y) causes a compile error because you cannot have an assignment statement inside a statement.
c. x = y in System.out.println(x = y) causes a runtime error because you cannot have an assignment statement inside a statement.
d. The program has a compile error because the return type of the clone() method is java.lang.Object.


d. The program has a compile error because the return type of the clone() method is java.lang.Object.
(A) is wrong because Date implements and Cloneable and overrides the clone() method. (B) and (C) are wrong because x = y is an assignment expression, which assigns y to x. (D) is correct. You have to cast it into Date in order to assign it to y.

Computer Science & Information Technology

You might also like to view...

In the three-way handshake, the first packet in the sequence has the ________ flag set.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Given the following character array

char[] h = {‘H’, ‘E’, ‘L’, ‘L’, ‘O’}; Write a Java statement that will create a new String object from the character array.

Computer Science & Information Technology

The __________ program combines the output of the compiler with various library functions to produce an executable program

What will be an ideal response?

Computer Science & Information Technology

When troubleshooting mobile wireless connections, which of these is unlikely to be a factor?

a. The device is within range of the wireless network. b. The correct SSID was entered (if manually connecting). c. The device supports the encryption protocol of the wireless network. d. The brands of the devices.

Computer Science & Information Technology