Shared Flashcard Set

Details

Java CS170 Chapter. 13-14
Quiz Questions
11
Computer Science
Undergraduate 2
12/09/2011

Additional Computer Science Flashcards

 


 

Cards

Term
When you use an enumerated type variable as a switch selector, the case labels in the switch body should use:
Answer

a. the fully-qualified enumerated type member names

b. integral constants

c. the unqualified enumerated type member names

d. integral constants or int literals
Definition
c. the unqualified enumerated type member names
Term
The members of an enumerated type are _______________.
Answer
a. constants
b. instance variables
c. fields
d. strings
Definition
a. constants
Term
When you assign values to an enumerated type variable, the values must be:
Answer
a. any reference type
b. members defined in the enumeration
c. Int
d. Object
e. String
Definition
b. members defined in the enumeration
Term
When you override a method defined in a superclass, you must do all of these except:
Answer

a. Use an access specifier that is at least as permissive as the superclass method

b. Return exactly the same type as the original method.

c. Use exactly the same number and type of parameters as the original method.

d. Change either the number, type, or order of parameters in the subclass.
Definition
d. Change either the number, type, or order of parameters in the subclass.
Term
A ____________ relationship exists between two classes when one class contains fields that are instances of the other class.
Answer

a. superclass-subclass

b. has-A

c. is-A

d. inheritance
Definition
b. has-A
Term
Inheritance gives your programs the ability to express _______________ between classes.
Answer

a. encapsulation

b. composition

c. dependencies

d. relationships
Definition
d. relationships
Term
To call a superclass method from a subclass method, when both methods have the same name and signature, prefix the call to the superclass method with:
Answer

a. this

b. base

c. the name of the superclass (that is, Person, if that is the name of the superclass)

d. no prefix is necessary. You cannot call an overridden superclass method from the subclass method you've overridden.

e. super
Definition
e. super
Term
To prevent subclasses from overriding an inherited method, the superclass can mark the method as:
Answer

a. static

b. public

c. protected

d. final

e. private
Definition
a. static
Term
Examine the following method. (Some lines may be syntactically incorrect.) You may assume that any necessary imports have already been added to the program. public void run() { GImage img = new GImage("b.gif"); ArrayList a; // I ArrayList b; // II a = new ArrayList(img); // III a = new ArrayList(img); // IV new ArrayList(); // V } Which lines correctly compile? Answer a. I, IV and V b. I only c. II and III only d. I and IV only
Definition
a. I, IV and V
Term
ArrayList objects can hold any object type. To store and retrieve int values in the collection, the ArrayList employs a technique called:
Answer

a. casting

b. coercion

c. boxing

d. setting

e. downcasting
Definition
c. boxing
Term
In the type-safe version of the ArrayList class, you specify the type of each element by:
Answer

a. specifying a generic type parameter when defining the ArrayList variable

b. using the setType() method once the ArrayList is constructed

c. passing a Class parameter as the first argument to the constructor

d. using the special type-safe version of the subscript operator

e. None of these; an ArrayList can hold any object type
Definition
a. specifying a generic type parameter when defining the ArrayList variable
Supporting users have an ad free experience!