Study Flashcards

1
Q

What index value is used to locate the last element in the nums ArrayList?

nums. length()-1
nums. length
nums. size()-1
nums. size()

A

nums.size()-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which method do you use to test if an element is in a set or list named x?

A) x.contain(element)

B) x.include(element)

C) (element instanceof List) || (element instanceof Set)

D) x.in(element)

E) x.contains(element)

A

E) x.contains(element)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the output of the following code?

double[] myList = {1, 5, 5, 5, 5, 1};
double max = myList[0];
int indexOfMax = 0;
for (int i = 1; I  max) {
       max = myList[I];
       indexOfMax = I;
}
}
A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which statement is the correct declaration and initialization of an ArrayList of String values?

A) ArrayList name;
name = ArrayList();

B) ArrayList name;
name = new ArrayList();
C) ArrayList name;
name = new ArrayList();
D) String name;
name = new String();
A
B) ArrayList name;
name = new ArrayList();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many elements are in array matrix (int[][] matrix = new int[5][5])?

A

25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many elements are in array double[] list = new double[5]?

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Suppose list is a LinkedList that contains 1 million int values. Analyze the following code:

A:
for (int I = 0; I < list.size(); I++)
sum += list.get(i);

B:
for (int i: list)
sum += I;

A) Code fragment A runs as fast as code fragment B.
B) Code fragment A runs faster than code fragment B.
C) Code fragment B runs faster than code fragment A.

A

C) Code fragment B runs faster than code fragment A.

Because code fragment B uses an iterator to traverse the elements in a linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the index variable for the element at the first row and first column in array a?

A) a[1][0]
B) a[0][1]
C) a[1][1]
D) a[0][0]

A

D) a[0][0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which statement below is the correct way to retrieve the first element in the nums ArrayList?

nums(0)

nums.get(0)

nums[0]

nums[1]

A

nums.get(0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?

A

3 and 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Regression testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine
(T/F)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A unit is object-oriented programming is usually considered as

A) a system
B) a class
C) an interface
D) a package
A

B) a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which one of the following best describes a feature provided by Junit?

A) Provides support for documenting source code
B) Provides support for refactoring code
C) Code compilation
D) Provides support to test drivers for running tests

A

D) Provides support to test drivers for running tests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

_______ models has-a relationships and represents an ownership relationship between two objects where the child can exist independently of the parent

A

Aggregation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

________ is a general binary relationship that describes an activity between two classes

A

Association

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

_________ models has-a relationships and represents an ownership relationship between two objects where the child cannot exist independent of the parent

A

Composition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

______ can be multi dimensional. (Array or ArrayList)

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

_______ has a contiguous memory location (Array or ArrayList)

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

________ cannot store primitive type (Array or ArrayList)

A

ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

________ holds the constant number of values of the same type (Array or ArrayList)

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

_______ can only be single dimensional (Array or ArrayList)

A

ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

_______ automatically grows and shrinks as needed (Array or ArrayList)

A

ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

________ an incorrect state of the system that could cause the system to fail.

A

Error

24
Q

_________ a piece of code that cause an incorrect state.

A

Fault

25
Q

________ occurs whenever the external behavior of a system does not conform to that prescribed in the system specification.

A

Failure

26
Q

___________ examine the program that is accessible from the outside and observe it externally visible outcome.

A

Blackbox testing

27
Q

____________ examine the source code to figure out what to test and how best to test the code.

A

Whitebox testing

28
Q

_________ wrapping up of data and operations on the data under a single unit

A

Encapsulation

29
Q

_________ Ability to take the form of itself, parent, grandparent, etc

A

Polymorphism

30
Q

__________ showing only essential information

A

Abstraction

31
Q

__________ acquiring all the properties and behaviors of a parent object

A

Inheritance

32
Q

The default value for data field of a boolean type, numeric type, object type is ________, respectively.

A

false, 0, null

33
Q

The order of methods in a class is immaterial. (T/F)

A

True

34
Q

Given the declaration Circle x = new Circle(), which of the following statement is most accurate?

A) x contains an object of the Circle type.
B) You can assign an int value to x.
C) x contains an int value.
D) x contains a reference to a Circle object.

A

D) x contains a reference to a Circle object.

35
Q

Multiple constructors can be defined in a class. (T/F)

A

True

36
Q

Constructors must have the same name as the class itself. (T/F)

A

True

37
Q

Constructors do not have a return type, not even void. (T/F)

A

True

38
Q

Constructors are invoked using the new operator when an object is created. (T/F)

A

True

39
Q

Analyze the following code:

public class Test {
public static void main(String[] args) {
A a = new A();
a.print();
}
}
class A {
String s;

A(String s) {
this.s = s;
}

void print() {
System.out.println(s);
}
}
[You can select multiple]	
A) The program compiles and runs fine and prints nothing.
B) The program has a compilation error because class A is not a public class.
C) The program has a compilation error because class A does not have a default constructor.
D) The program would compile and run if you change A a = new A() to A a = new A("5").
A
C) The program has a compilation error because class A does not have a default constructor.
D) The program would compile and run if you change A a = new A() to A a = new A("5").
40
Q

Given the ArrayList nums with the values [3, 7, 6, 0], what code below is the proper way to change the 6 to be a 5?

nums. set(2, 5)
nums. set(6, 5)
nums. set(5, 2)

nums[2] = 5

A

nums.set(2, 5)

41
Q

An ArrayList can grow automatically. (T/F)

A

True

42
Q

// Which index of the array holds the value of 5?

int [] numbers = new int[10];

for(int i=0; i<10; i++)
numbers[i] = 2 * i + 1;

A

2

43
Q

Which method do you use to remove an element from a set or list named x?

A

x.remove(element)

44
Q

Which method do you use to test if an element is in a set or list named x?

A

x.contains(element)

45
Q

What is the output of the following code?

ArrayList list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.remove(2);
System.out.println(list);
A

[1, 2]

46
Q

Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length?

A

2, 3, and 4

47
Q

Suppose ArrayList x contains three strings [Beijing, Singapore, Tokyo]. Which of the following methods will cause runtime errors?

[You can pick multiple]

A) x.set(3, "New York");
B) x.remove(3)
C) x.get(3)
D) x.get(2)
E) x.size()
A

A) x.set(3, “New York”);
B) x.remove(3)
C) x.get(3)

48
Q

An ArrayList can shrink automatically. (T/F)

A

True

49
Q

Which one of the following best describes a feature provided by Junit?

Provides support to test drivers for running tests

Code compilation

Provides support for documenting source code

Provides support for refactoring code

A

Provides support to test drivers for running tests

50
Q

Regression testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine. (T/F)

A

True

51
Q

A unit is object-oriented programming is usually considered as

an interface

a system

a package

a class

A

a class

52
Q

________ represents an entity in the real world that can be distinctly identified.

A) A class
B) A data field
C) A method
D) An object

A

D) An object

53
Q

To prevent a class from being instantiated, ________.

A) use the public modifier on the constructor
B) use the private modifier on the constructor
C) don’t use any modifiers on the constructor
D) use the static modifier on the constructor

A

B) use the private modifier on the constructor

54
Q

You can create an instance of the Math class. (T/F)

A

False

55
Q

A unit is object-oriented programming is usually considered as

a system

a class

a package

an interface

A

a class