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?

```
1 import java.util.*;
2 public class Test {
3 public static void main(String[] args) {
4 Calendar[] calendars = new Calendar[10];
5 calendars[0] = new Calendar();
6 calendars[1] = new GregorianCalendar();
7 }
8 }```
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 (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...

An id selector must always be preceded by a(n) ________ character

Fill in the blank(s) with correct word

Computer Science & Information Technology

Using public set methods helps provide data integrity if:

a. The instance variables are public. b. The instance variables are private. c. The methods perform validity checking. d. Both b and c.

Computer Science & Information Technology