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.
You might also like to view...
Which of the following initializes a vector
a. vector integers{1, 2, 3, 4, 5, 6};
b. vector
In Prolog, the __________ describes the relationship between the _________.
A. argument, predicates B. predicate, rules C. rule, arguments D. predicate, arguments