NEW
Font size
WorksheetsOOPROG21 - MIDTERM
Total questions: 75
Worksheet time: 38mins
After you create an array variable, you still need to ____ memory space.
create
organize
reserve
dump
When you declare or access an array, you can use any expression to represent the size, as long as the expression is ____.
a variable
enclosed in brackets
an integer
a list
Languages such as Visual Basic, BASIC, and COBOL use ____ to refer to individual array elements.
()
[]
{}
<>
A(n) ____ is an integer contained within square brackets that indicates one of an array’s variables.
postscript
subscript
variable header
indicator
When you declare an array name, no computer memory address is assigned to it. Instead, the array variable name has the special value ____, or Unicode value ‘\u0000’.
empty
null
false
zero
In Java, boolean array elements automatically are assigned the value ____.
null
\u0000
true
false
When you create an array of objects, each reference is assigned the value ____.
null
\u0000
true
false
You use a ____ following the closing brace of an array initialization list.
.
;
;
,
Providing values for all the elements in an array is called ____ the array.
populating
declaring
filling
irrigating
When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the value is passed.
array
dummy
element
primitive
The length ____ contains the number of elements in the array.
box
field
area
block
A(n) ____ loop allows you to cycle through an array without specifying the starting and ending points for the loop control variable.
do...while
inner
enhanced for
enhanced while
If a class has only a default constructor, you must call the constructor using the keyword ____ for each declared array element.
default
new
first
object
Comparing a variable to a list of values in an array is a process called ____ an array.
validating
using
checking
searching
A ____ array is one with the same number of elements as another, and for which the values in corresponding elements are related.
cloned
parallel
property
two-dimensional
When you initialize parallel arrays, it is convenient to use ____ so that the values that correspond to each other visually align on the screen or printed page.
tabs
indentation
spacing
dashes
When you perform a ____, you compare a value to the endpoints of numerical ranges to find the category in which a value belongs.
range match
sort
reference
search
It is a good programming practice to ensure that a subscript to an array does not fall below zero, causing a(n) ____.
array dump
runtime error
conundrum
compiling error
Individual array elements are ____ by value when a copy of the value is made and used within the receiving method.
sorted
passed
received
stored
When any primitive type variable is passed to a method, the ____ is passed.
value
reference
location
memory
When a method returns an array reference, you include ____ with the return type in the method header.
{}
()
<>
[]
Which of the following println statements will display the last myScores element in an array of 10?
System.out.println(vals[0]);
System.out.println(vals[1]);
System.out.println(vals[9]);
System.out.println(vals[10]);
Which of the following statements correctly declares and creates an array to hold five double scores values?
integer[] scores = new double[5]
double[] scores = new integer[5]
double[] = new scores[5]
double[] scores = new double[5]
Which of the following statements correctly initializes an array with an initialization list?
int[] nums = {2, 4, 8};
int[] nums = (2, 4, 8);
int nums = [2, 4, 8];
int nums() = int{2, 4, 8}
In which of the following statements is the value of myVals null?
int myVals = ""
int [] myVals;
myVals = int[null]
int[null] = myVals
____ is the process of arranging a series of objects in some logical order.
Passing
Organizing
Sorting
Indexing
In a(n) ____ , you repeatedly compare pairs of items, swapping them if they are out of order, eventually creating a sorted list.
range match
bubble sort
enhanced for loop
float sort
An array that you can picture as a column of values, and whose elements you can access using one subscript, is a ____ array.
single-dimensional
two-dimensional
parallel
column
When mathematicians use a two-dimensional array, they often call it a ____.
grid
net
matrix
mesh
How would you create an array named someNumbers that holds three rows and four columns?
int[][] someNumbers = new int[4][3]
int[][] someNumbers = new int[3][4]
int[] someNumbers = new int[3][4]
double[][] someNumbers = new int[3][4]
To declare a two-dimensional array in Java, you type two sets of ____ after the array type.
{ }
[ ]
( )
< >
With a two-dimensional array, the ____ field holds the number of rows in the array.
size
capacity
row
length
Which Java statement creates a ragged array with six rows?
double [][] sales = new double[6][4]
double [][] sales = new double[4][6]
double [][] sales = new double[6][]
double [][] sales = new double[][6]
The Arrays class ____ method puts a particular value in each element of the array.
binarySearch
fill
equals
search
The Arrays class ____ methods are a new feature in Java 8 that makes sorting more efficient when thousands or millions of objects need to be sorted.
compare
equals
parallelSort
fill
The negative integer returned by the binarySearch() method when the value is not found is the negative equivalent of the array ____.
type
scope
size
length
Programmers often refer to a ____ search as a “divide and conquer” procedure.
bubble
binary
division
split
You can add an item at any point in a(n) ____ container and the array size expands automatically to accommodate the new item.
ArrayList
Array
ResizableArray
array
An ArrayList’s ____ is the number of items it can hold without having to increase its size.
length
buffer
capacity
size
The ArrayList class ____ method removes an item from an ArrayList at a specified location.
delete
get
erase
remove
The ArrayList class ____ method retrieves an item from a specified location in an ArrayList.
extract
get
peek
retrieve
The ArrayList class ____ method returns the current ArrayList size.
size
capacity
length
rows
In Java, you create an enumerated data type in a statement that uses the keyword ____.
new
sequence
collection
enum
Regarding enumerations, the ____ method returns an integer that represents the constant’s position in the list of constants; as with arrays, the first position is 0.
valueAt
positionOf
ordinal
indexOf
Regarding enumerations, the ____ method returns the name of the calling constant object.
toString
constName
ordinal
nameOf
Which of the following describes a data type for which only appropriate behaviors are allowed?
value-neutral
type-safe
enumerated
data-cast
int[][] myVals = {{2, 4, 6, 8}, {20, 40, 60, 80} }; Using the above two-dimensional array, what is the value of myVals[1][2]?
4
60
6
40
double[][] empSales = new double[5][]; The above statement declares a(n) ____ array.
insertion
sort
ragged
boolean
int[][] myVals = {{2, 4, 6}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals.length?
1
2
4
5
int[][] myVals = {{2, 4, 6}, {1, 8, 9}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals[1].length?
1
7
3
4
____ is a mechanism that enables one class to acquire all the behaviors and attributes of another class.
Inheritance
Polymorphism
Encapsulation
Override
When you create a class by making it inherit from another class, the new class automatically contains the data fields and ____ of the original class.
fonts
methods
class names
arrays
By convention, a class diagram contains the ____ following each attribute or method.
data field
argument
data type
class
Arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the original class.
method diagram
UML diagram
virtual method call
composition
The ability to use inheritance in Java makes programs easier to write, ____, and more quickly understood.
faster
more secure
more robust
less error prone
The class used as a basis for inheritance is the ____ class.
child
extends
base
derived
You use the keyword ____ to achieve inheritance in Java.
inherit
extends
super
public
Sometimes the superclass data fields and methods are not entirely appropriate for the subclass objects; in these cases, you want to ____ the parent class members.
negate
overrule
overrid e
hide
If a programming language does not support ____, the language is not considered object-oriented.
syntax
applets
loops
polymorphism
____ polymorphism is the ability of one method to work appropriately for subclasses of the same parent class.
Subtype
Name
Supertype
Override
When you create parent and child classes of your own, the child classes use ____ constructors.
two
three
four
six
When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.
constructor
argument
header
name
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.
objects
data fields
methods
constructors
You can use the keyword ______ within a method in a derived class to access an overridden method in a base class.
sub
this
protected
super
When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.
virtual method calls
polymorphism
information hiding
inlining
Using the keyword ____ provides you with an intermediate level of security between public and private access.
protected
this
super
secure
The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: ____ members of the parent class are not accessible within a child class’s methods.
private
public
final
protected
If a ____ method has the same name as a parent class method and you use the name with a child class object, the child method hides the original.
final
static
protected
private
You can use the ____ modifier with methods when you don’t want the method to be overridden.
override
access
final
end
You are never aware that ____ is taking place; the compiler chooses to use this procedure to save the overhead of calling a method.
information hiding
polymorphism
overriding
inlining
Which of the following statements will create a class named Red that is based on the class Color?
public class Red extends Color
public Red class extends Color
public Color class expands Red
public extend Red class Color
Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?
superclass(name, score);
subclass(name, score);
extends(name, score);
super(name, score);
If jrStudent is an object of Student, which of the following statements will result in a value of true?
Student = instanceof jrStudent
jrStudent instanceof Student
instanceof Student = jrStudent
Student instanceof jrStudent
Which statement correctly declares a sedan object of the Car class?
sedan Car = new sedan();
sedan Car = new sedan();
Car sedan = new Car();
new sedan() = Student;
You would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
private or protected
private
protected
public
