The java.util.Calendar and java.util.GregorianCalendar classes are introduced in Chapter 11. Analyze the following code. Which of the following statements is correct?

```
import java.util.*;
public class Test {
public static void main(String[] args) {
Calendar[] calendars = new Calendar[10];
calendars[0] = new Calendar();
calendars[1] = new GregorianCalendar();
}
}
```
a. The program has a compile error on Line 4 because java.util.Calendar is an abstract class.
b. The program has a compile error on Line 5 because java.util.Calendar is an abstract class.
c. The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type.
d. The program has no compile errors.


b. The program has a compile error on Line 5 because java.util.Calendar is an abstract class.
(A) is incorrect since it is OK to use abstract class as data type for arrays. new Calendar[10] does not create Calendar objects. It just creates an array with 10 elements, each of which can reference to a Calendar object. (B) is correct since you cannot create an object from an abstract class. (C) is incorrect since it is fine to create a GregorianCalendar object and assign its reference to a variable of its superclass type.

Computer Science & Information Technology

You might also like to view...

Which of the following is not one of the six logical units of a computer?

a. Input unit. b. Output unit. c. Central processing unit. d. Printer unit.

Computer Science & Information Technology

________ tags are tags between other tags.

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

Computer Science & Information Technology

The OneNote App will have to be configured to work with the OneNote 2013 application

Indicate whether the statement is true or false

Computer Science & Information Technology

Cloud computing has the potential to free end users from owning, maintaining, and storing software and data.

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

Computer Science & Information Technology