Deck 3: Introduction to Collections - Stacks
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/49
Play
Full screen (f)
Deck 3: Introduction to Collections - Stacks
1
What is the principle difference in behavior between a stack and a queue?
A) a stack reverses order whereas a queue preserves order
B) a stack does nothing whereas a queue can preserve and reverse order
C) there is no difference
D) a stack preserves order whereas a queue reverses order
A) a stack reverses order whereas a queue preserves order
B) a stack does nothing whereas a queue can preserve and reverse order
C) there is no difference
D) a stack preserves order whereas a queue reverses order
a stack reverses order whereas a queue preserves order
2
Stacks operate as _______________.
A) Last Out, First In
B) First In, First Out
C) Last In, First Out
D) None of the above
A) Last Out, First In
B) First In, First Out
C) Last In, First Out
D) None of the above
Last Out, First In
3
A ______ can be used to reverse the order of a set of data.
A) Queue
B) Stack
C) Software
D) Heaps
A) Queue
B) Stack
C) Software
D) Heaps
Stack
4
A pop operation on a Stack returns a(n)
A) node
B) element
C) variable
D) pointer
A) node
B) element
C) variable
D) pointer
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
5
To add an element to a stack you use the method.
A) push
B) pop
C) peek
D) size
A) push
B) pop
C) peek
D) size
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following is the correct way to instantiate an array of 10 generic objects?
A) T[] x = new T[10];
B) T[10] x = new T[];
C) T[] x = (T[])(new object[10]);
D) None of the above
A) T[] x = new T[10];
B) T[10] x = new T[];
C) T[] x = (T[])(new object[10]);
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
7
Elements in a collection are typically organized by
A) the order of their addition to the collection
B) by some inherent relationship among the elements
C) randomly
D) A and B
E) None of the above
A) the order of their addition to the collection
B) by some inherent relationship among the elements
C) randomly
D) A and B
E) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
8
A polymorphic reference uses _______________, not the type of the reference, to determine which version of a method to invoke.
A) the type of the object
B) the type of the reference
C) both A and B
D) none of the above
A) the type of the object
B) the type of the reference
C) both A and B
D) none of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
9
In an array implementation of a Stack, the array is ___________ causing the implementation to have to create a new larger array and copy the contents of the stack into the new array in order to expand the capacity of the stack.
A) Dynamic
B) Static
C) Flexible
D) Polymorphic
A) Dynamic
B) Static
C) Flexible
D) Polymorphic
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
10
The variable top in the array implementation of a Stack refers to
A) The next available position in the array
B) The item at the top of the Stack
C) The number of items in the stack
D) A and C
E) None of the above
A) The next available position in the array
B) The item at the top of the Stack
C) The number of items in the stack
D) A and C
E) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
11
A ______ is an object that gathers and organizes other objects.If you were to place elements on a collection and then wanted to reverse the order, would it be better to use a Stack or a Queue?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
12
What are the 3 primary methods for a stack?_______
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
13
If an exception occurs during the execution of a java program and is not handled in the method where it occurs, the exception will be ______.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
14
A __ is a Java language element used to group related classes under a common name.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
15
The term polymorphism refers to a reference variable that can point to different types of objects. This can be accomplished in Java through the use of ____ and ____.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
16
A collection is an ______ where the details of the implementation are hidden.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
17
____ is the process of deriving a new class from an existing one.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
18
One purpose of inheritance is to ____ existing software.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
19
______ and ______ represent unusual or invalid processing.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
20
The messages printed by a thrown exception indicate the nature of the problem and provide a method _______.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
21
Each ______ on a try statement handles a particular kind of exception that may be thrown within the try block.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
22
A Java interface defines a set of ______ methods and is useful in separating the concept of an abstract data type from its implementation.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
23
All Java classes are derived, directly or indirectly, from the ______ class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
24
The toString and equals methods are defined in the Object class and therefore are ______ by every class in every Java program.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
25
By using the interface name as a return type, the interface doesn't commit the method to the use of any particular class that implements a stack.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
26
If an exception is not caught and handled where it occurs, it is propagated to the calling method.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
27
The implementation of the collection operations should affect the way users interact with the collection.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
28
A well-defined interface masks the implementation of the collection.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
29
An array dynamically grows as needed and essentially has no capacity limitations.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
30
The pop operation is implemented by returning a reference to the element currently stored at the top of the stack and adjusting the top reference to the new top of the stack.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
31
A data structure is the underlying programming construct used to implement a collection.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
32
Stack elements are processed in a FIFO manner-the first element in is the first element out.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
33
Inherited variables and methods can be used in the derived class as if they had been declared locally.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
34
Inheritance creates an is-a relationship between all parent and child classes.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
35
Common features should be located as low in a class hierarchy as is reasonable, minimizing maintenance efforts.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
36
The most efficient way to implement an array-based stack keeps the top of the stack at the position 0 of the array?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
37
What is a collection?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
38
What is a data type?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
39
What is abstraction and what advantage does it provide?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
40
Why is a class an excellent representation of an abstract data type?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
41
What is the characteristic behavior of a stack?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
42
What are some of the other operations that might be implemented for a stack?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
43
Define inheritance.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
44
Define polymorphism.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
45
Given the example in Figure 3.5, list the subclasses of Mammal.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
46
Given the example in Figure 3.5, will the following code compile?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
47
Given the example in Figure 3.5, will the following code compile?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
48
What is the purpose of Generics in the Java language?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
49
What is the advantage of postfix notation?
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck