wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

OOPROG21 - MIDTERM

Total questions: 75

Worksheet time: 38mins

Name
Class
Date
1.

After you create an array variable, you still need to ____ memory space.

a)

create

b)

organize

c)

reserve

d)

dump

2.

When you declare or access an array, you can use any expression to represent the size, as long as the expression is ____.

a)

a variable

b)

enclosed in brackets

c)

an integer

d)

a list

3.

Languages such as Visual Basic, BASIC, and COBOL use ____ to refer to individual array elements.

a)

()

b)

[]

c)

{}

d)

<>

4.

A(n) ____ is an integer contained within square brackets that indicates one of an array’s variables.

a)

postscript

b)

subscript

c)

variable header

d)

indicator

5.

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

a)

empty

b)

null

c)

false

d)

zero

6.

In Java, boolean array elements automatically are assigned the value ____.

a)

null

b)

\u0000

c)

true

d)

false

7.

When you create an array of objects, each reference is assigned the value ____.

a)

null

b)

\u0000

c)

true

d)

false

8.

You use a ____ following the closing brace of an array initialization list.

a)

.

b)

;

c)

;

d)

,

9.

Providing values for all the elements in an array is called ____ the array.

a)

populating

b)

declaring

c)

filling

d)

irrigating

10.

When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the value is passed.

a)

array

b)

dummy

c)

element

d)

primitive

11.

The length ____ contains the number of elements in the array.

a)

box

b)

field

c)

area

d)

block

12.

A(n) ____ loop allows you to cycle through an array without specifying the starting and ending points for the loop control variable.

a)

do...while

b)

inner

c)

enhanced for

d)

enhanced while

13.

If a class has only a default constructor, you must call the constructor using the keyword ____ for each declared array element.

a)

default

b)

new

c)

first

d)

object

14.

Comparing a variable to a list of values in an array is a process called ____ an array.

a)

validating

b)

using

c)

checking

d)

searching

15.

A ____ array is one with the same number of elements as another, and for which the values in corresponding elements are related.

a)

cloned

b)

parallel

c)

property

d)

two-dimensional

16.

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.

a)

tabs

b)

indentation

c)

spacing

d)

dashes

17.

When you perform a ____, you compare a value to the endpoints of numerical ranges to find the category in which a value belongs.

a)

range match

b)

sort

c)

reference

d)

search

18.

It is a good programming practice to ensure that a subscript to an array does not fall below zero, causing a(n) ____.

a)

array dump

b)

runtime error

c)

conundrum

d)

compiling error

19.

Individual array elements are ____ by value when a copy of the value is made and used within the receiving method.

a)

sorted

b)

passed

c)

received

d)

stored

20.

When any primitive type variable is passed to a method, the ____ is passed.

a)

value

b)

reference

c)

location

d)

memory

21.

When a method returns an array reference, you include ____ with the return type in the method header.

a)

{}

b)

()

c)

<>

d)

[]

22.

Which of the following println statements will display the last myScores element in an array of 10?

a)

System.out.println(vals[0]);

b)

System.out.println(vals[1]);

c)

System.out.println(vals[9]);

d)

System.out.println(vals[10]);

23.

Which of the following statements correctly declares and creates an array to hold five double scores values?

a)

integer[] scores = new double[5]

b)

double[] scores = new integer[5]

c)

double[] = new scores[5]

d)

double[] scores = new double[5]

24.

Which of the following statements correctly initializes an array with an initialization list?

a)

int[] nums = {2, 4, 8};

b)

int[] nums = (2, 4, 8);

c)

int nums = [2, 4, 8];

d)

int nums() = int{2, 4, 8}

25.

In which of the following statements is the value of myVals null?

a)

int myVals = ""

b)

int [] myVals;

c)

myVals = int[null]

d)

int[null] = myVals

26.

____ is the process of arranging a series of objects in some logical order.

a)

Passing

b)

Organizing

c)

Sorting

d)

Indexing

27.

In a(n) ____ , you repeatedly compare pairs of items, swapping them if they are out of order, eventually creating a sorted list.

a)

range match

b)

bubble sort

c)

enhanced for loop

d)

float sort

28.

An array that you can picture as a column of values, and whose elements you can access using one subscript, is a ____ array.

a)

single-dimensional

b)

two-dimensional

c)

parallel

d)

column

29.

When mathematicians use a two-dimensional array, they often call it a ____.

a)

grid

b)

net

c)

matrix

d)

mesh

30.

How would you create an array named someNumbers that holds three rows and four columns?

a)

int[][] someNumbers = new int[4][3]

b)

int[][] someNumbers = new int[3][4]

c)

int[] someNumbers = new int[3][4]

d)

double[][] someNumbers = new int[3][4]

31.

To declare a two-dimensional array in Java, you type two sets of ____ after the array type.

a)

{ }

b)

[ ]

c)

( )

d)

< >

32.

With a two-dimensional array, the ____ field holds the number of rows in the array.

a)

size

b)

capacity

c)

row

d)

length

33.

Which Java statement creates a ragged array with six rows?

a)

double [][] sales = new double[6][4]

b)

double [][] sales = new double[4][6]

c)

double [][] sales = new double[6][]

d)

double [][] sales = new double[][6]

34.

The Arrays class ____ method puts a particular value in each element of the array.

a)

binarySearch

b)

fill

c)

equals

d)

search

35.

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.

a)

compare

b)

equals

c)

parallelSort

d)

fill

36.

The negative integer returned by the binarySearch() method when the value is not found is the negative equivalent of the array ____.

a)

type

b)

scope

c)

size

d)

length

37.

Programmers often refer to a ____ search as a “divide and conquer” procedure.

a)

bubble

b)

binary

c)

division

d)

split

38.

You can add an item at any point in a(n) ____ container and the array size expands automatically to accommodate the new item.

a)

ArrayList

b)

Array

c)

ResizableArray

d)

array

39.

An ArrayList’s ____ is the number of items it can hold without having to increase its size.

a)

length

b)

buffer

c)

capacity

d)

size

40.

The ArrayList class ____ method removes an item from an ArrayList at a specified location.

a)

delete

b)

get

c)

erase

d)

remove

41.

The ArrayList class ____ method retrieves an item from a specified location in an ArrayList.

a)

extract

b)

get

c)

peek

d)

retrieve

42.

The ArrayList class ____ method returns the current ArrayList size.

a)

size

b)

capacity

c)

length

d)

rows

43.

In Java, you create an enumerated data type in a statement that uses the keyword ____.

a)

new

b)

sequence

c)

collection

d)

enum

44.

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.

a)

valueAt

b)

positionOf

c)

ordinal

d)

indexOf

45.

Regarding enumerations, the ____ method returns the name of the calling constant object.

a)

toString

b)

constName

c)

ordinal

d)

nameOf

46.

Which of the following describes a data type for which only appropriate behaviors are allowed?

a)

value-neutral

b)

type-safe

c)

enumerated

d)

data-cast

47.

int[][] myVals = {{2, 4, 6, 8}, {20, 40, 60, 80} }; Using the above two-dimensional array, what is the value of myVals[1][2]?

a)

4

b)

60

c)

6

d)

40

48.

double[][] empSales = new double[5][]; The above statement declares a(n) ____ array.

a)

insertion

b)

sort

c)

ragged

d)

boolean

49.

int[][] myVals = {{2, 4, 6}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals.length?

a)

1

b)

2

c)

4

d)

5

50.

int[][] myVals = {{2, 4, 6}, {1, 8, 9}, {1, 3, 5, 7}}; Using the above array, what is the value of myVals[1].length?

a)

1

b)

7

c)

3

d)

4

51.

____ is a mechanism that enables one class to acquire all the behaviors and attributes of another class.

a)

Inheritance

b)

Polymorphism

c)

Encapsulation

d)

Override

52.

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.

a)

fonts

b)

methods

c)

class names

d)

arrays

53.

By convention, a class diagram contains the ____ following each attribute or method.

a)

data field

b)

argument

c)

data type

d)

class

54.

Arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the original class.

a)

method diagram

b)

UML diagram

c)

virtual method call

d)

composition

55.

The ability to use inheritance in Java makes programs easier to write, ____, and more quickly understood.

a)

faster

b)

more secure

c)

more robust

d)

less error prone

56.

The class used as a basis for inheritance is the ____ class.

a)

child

b)

extends

c)

base

d)

derived

57.

You use the keyword ____ to achieve inheritance in Java.

a)

inherit

b)

extends

c)

super

d)

public

58.

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.

a)

negate

b)

overrule

c)

overrid e

d)

hide

59.

If a programming language does not support ____, the language is not considered object-oriented.

a)

syntax

b)

applets

c)

loops

d)

polymorphism

60.

____ polymorphism is the ability of one method to work appropriately for subclasses of the same parent class.

a)

Subtype

b)

Name

c)

Supertype

d)

Override

61.

When you create parent and child classes of your own, the child classes use ____ constructors.

a)

two

b)

three

c)

four

d)

six

62.

When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.

a)

constructor

b)

argument

c)

header

d)

name

63.

Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

a)

objects

b)

data fields

c)

methods

d)

constructors

64.

You can use the keyword ______ within a method in a derived class to access an overridden method in a base class.

a)

sub

b)

this

c)

protected

d)

super

65.

When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.

a)

virtual method calls

b)

polymorphism

c)

information hiding

d)

inlining

66.

Using the keyword ____ provides you with an intermediate level of security between public and private access.

a)

protected

b)

this

c)

super

d)

secure

67.

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.

a)

private

b)

public

c)

final

d)

protected

68.

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.

a)

final

b)

static

c)

protected

d)

private

69.

You can use the ____ modifier with methods when you don’t want the method to be overridden.

a)

override

b)

access

c)

final

d)

end

70.

You are never aware that ____ is taking place; the compiler chooses to use this procedure to save the overhead of calling a method.

a)

information hiding

b)

polymorphism

c)

overriding

d)

inlining

71.

Which of the following statements will create a class named Red that is based on the class Color?

a)

public class Red extends Color

b)

public Red class extends Color

c)

public Color class expands Red

d)

public extend Red class Color

72.

Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?

a)

superclass(name, score);

b)

subclass(name, score);

c)

extends(name, score);

d)

super(name, score);

73.

If jrStudent is an object of Student, which of the following statements will result in a value of true?

a)

Student = instanceof jrStudent

b)

jrStudent instanceof Student

c)

instanceof Student = jrStudent

d)

Student instanceof jrStudent

74.

Which statement correctly declares a sedan object of the Car class?

a)

sedan Car = new sedan();

b)

sedan Car = new sedan();

c)

Car sedan = new Car();

d)

new sedan() = Student;

75.

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?

a)

private or protected

b)

private

c)

protected

d)

public