The GeometricObject and Circle classes are defined in this chapter. Analyze the following code. Which statements are correct?

```
public class Test {
public static void main(String[] args) {
GeometricObject x = new Circle(3);
GeometricObject y = (Circle)(x.clone());
System.out.println(x);
System.out.println(y);
}
}
```
a. The program has a compile error because the clone() method is protected in the Object class.
b. After you override the clone() method and make it public in the Circle class, the problem can compile and run just fine, but y is null if Circle does not implement the Cloneable interface.
c. To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable interface.
d. If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work fine to clone Circle objects.


a. The program has a compile error because the clone() method is protected in the Object class.
b. After you override the clone() method and make it public in the Circle class, the problem can compile and run just fine, but y is null if Circle does not implement the Cloneable interface.
c. To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable interface.
d. If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work fine to clone Circle objects.

Computer Science & Information Technology

You might also like to view...

When you do NOT want some recipients' names to appear in the header, enter those recipients' e-mail addresses in the Cc: box.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

To close all tabs except one, press and hold [option], then click ____ on the tab for the Web page you want to keep open.

A.
B.
C.
D.

Computer Science & Information Technology

____ is a data interchange format that allows you to exchange data between dissimilar systems or applications.

A. HTML B. CSV C. RTF D. XML

Computer Science & Information Technology

____ control keys let you control the playback of digital music or video; they might also include keys for controlling the volume and screen brightness. Function

A. Internet B. Navigation C. Media D. Function

Computer Science & Information Technology