CS 2114 Final Review Exam Questions With
Complete Answers
When do you use an interface? - ANSWER when several classes have the same
method signatures but implement all
the methods differently
When do you use an abstract class? - ANSWER when several classes have
identical methods and a few methods that need
to be implemented differently
Where does a queue add new items? - ANSWER at the back
The node that is easiest to access in a linked chain is - ANSWER the head node
In the Ch 6 linked chain implementation of a Stack ADT, the performance of
popping an entry from the stack is - ANSWER O(1)
In the Ch 6 linked chain implementation of a Stack ADT, when a node is popped
from the stack - ANSWER (1) the original first node will no longer be referenced
(2) the original first node will be deallocated
(3) the first node will reference what was second node in the chain
when an interface is used as a data type what methods can you invoke? -
ANSWER only methods of the interface
TRUE or FALSE... Several classes can implement the same interface - ANSWER
TRUE
TRUE or FALSE... One class can implement several interfaces - ANSWER TRUE
Recursive methods need - ANSWER a base case
In the Ch 6 array based implementation of a Stack ADT, what value for the
topIndex of the stack indicates that it is empty? - ANSWER -1
In the Ch 6 array-based implementation of a Stack ADT, the entry peek returns
what is be found at - ANSWER the last occupied location in the array
Polymorphism is when the type of the instance is determined at - ANSWER
runtime
, At _______ the variable type is checked to make sure the methods invoked
exist - ANSWER compile time
At _______ the JVM looks at the object's type to determine which method
implementation to call - ANSWER runtime
What does a primitive type represent? - ANSWER Simple indecomposable type
What does a reference type represent? - ANSWER A memory address instead of
the actual item stored at that address
The operator == tests to see if - ANSWER Two variables reference the same
place in the computer's memory
A class uses composition when it - ANSWER Declares an instance of another
class as a data field
Composition - ANSWER has-a relationship
inheritance - ANSWER is-a relationship
Why do we use inheritance? - ANSWER To have a general class with common
properties and behaviors shared by multiple more specialized classes.
calls the constructor of the parent class that takes no arguments - ANSWER
super();
calls the constructor of the current class that takes no arguments - ANSWER
this();
when one method has the same name but a different set of parameters than a
second method - ANSWER the methods are overloaded
a key benefit of inheritance is - ANSWER an object can have several types, it is
type compatible with any of its superclasses
encapsulation - ANSWER design principle that encloses data and methods
within a class, thereby hiding the class' implementation details
abstraction - ANSWER focus on what and not how
client interface - ANSWER what client code needs to know to use a class
implementation - ANSWER all the data fields and details of the method
definitions
Complete Answers
When do you use an interface? - ANSWER when several classes have the same
method signatures but implement all
the methods differently
When do you use an abstract class? - ANSWER when several classes have
identical methods and a few methods that need
to be implemented differently
Where does a queue add new items? - ANSWER at the back
The node that is easiest to access in a linked chain is - ANSWER the head node
In the Ch 6 linked chain implementation of a Stack ADT, the performance of
popping an entry from the stack is - ANSWER O(1)
In the Ch 6 linked chain implementation of a Stack ADT, when a node is popped
from the stack - ANSWER (1) the original first node will no longer be referenced
(2) the original first node will be deallocated
(3) the first node will reference what was second node in the chain
when an interface is used as a data type what methods can you invoke? -
ANSWER only methods of the interface
TRUE or FALSE... Several classes can implement the same interface - ANSWER
TRUE
TRUE or FALSE... One class can implement several interfaces - ANSWER TRUE
Recursive methods need - ANSWER a base case
In the Ch 6 array based implementation of a Stack ADT, what value for the
topIndex of the stack indicates that it is empty? - ANSWER -1
In the Ch 6 array-based implementation of a Stack ADT, the entry peek returns
what is be found at - ANSWER the last occupied location in the array
Polymorphism is when the type of the instance is determined at - ANSWER
runtime
, At _______ the variable type is checked to make sure the methods invoked
exist - ANSWER compile time
At _______ the JVM looks at the object's type to determine which method
implementation to call - ANSWER runtime
What does a primitive type represent? - ANSWER Simple indecomposable type
What does a reference type represent? - ANSWER A memory address instead of
the actual item stored at that address
The operator == tests to see if - ANSWER Two variables reference the same
place in the computer's memory
A class uses composition when it - ANSWER Declares an instance of another
class as a data field
Composition - ANSWER has-a relationship
inheritance - ANSWER is-a relationship
Why do we use inheritance? - ANSWER To have a general class with common
properties and behaviors shared by multiple more specialized classes.
calls the constructor of the parent class that takes no arguments - ANSWER
super();
calls the constructor of the current class that takes no arguments - ANSWER
this();
when one method has the same name but a different set of parameters than a
second method - ANSWER the methods are overloaded
a key benefit of inheritance is - ANSWER an object can have several types, it is
type compatible with any of its superclasses
encapsulation - ANSWER design principle that encloses data and methods
within a class, thereby hiding the class' implementation details
abstraction - ANSWER focus on what and not how
client interface - ANSWER what client code needs to know to use a class
implementation - ANSWER all the data fields and details of the method
definitions