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...

If the superclass contains only abstract method declarations, the superclass is used for ________.

a. implementation inheritance. b. interface inheritance. c. Both. d. Neither.

Computer Science & Information Technology

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

1. Elements of a vector must be of a primitive type, such as int, double, or char. 2. The AbstractSequentialList class provides efficient implementation of sequentially moving through the list at the expense of having inefficient implementation of random access to elements.

Computer Science & Information Technology

Answer the following questions for the certification report shown here.


a. What is the length of pair 7–8?
b. What is the propagation delay of pair 4–5?
c. Why did this cable fail the test?

Computer Science & Information Technology

Which of the following is an example of computer-initiated criminal activity?

a. spreading viruses b. stealing home addresses c. wire transfers d. spamming

Computer Science & Information Technology