AP Computer Science Final Exam

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/79

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

80 Terms

1
New cards

Inheritance is the process of sharing methods and instance variables between a base class
and its subclasses (T/F).

True

2
New cards

The name of the text file with Java source code must match the name of the program with a
.class extension (T/F).

False

3
New cards

Both for loops and while loops can be used as count-controlled loops (T/F).

True

4
New cards

It is illegal to declare several variables in a single declaration, i.e. int a, b, c;

False

5
New cards

m++, m=m+1, and m+=1 are all equivalent expressions (T/F).

True

6
New cards

The assignment operator ( = ) and equal to operator ( == ) can be used interchangeably (T/F).

False

7
New cards

A while loop will always execute at least once (T/F).

False

8
New cards

The counter in a for loop is updated at the beginning of the loop (T/F).

False

9
New cards

It is illegal to declare the loop control variable inside the for loop header (T/F).

False

10
New cards

The for statement combines counter initialization, condition test and counter update into a single expression (T/F).

True

11
New cards

It is usually safer to use the == or != operators in loops, rather than the other logical operators (T/F).

False

12
New cards

The identity of an object is simply the variable that references the object (T/F).

False

13
New cards

A class's implementation details can be changed radically without affecting any of its clients provided its interface remains the same (T/F).

True

14
New cards

The keyword public indicates that the class is accessible to all potential clients (T/F).

True

15
New cards

Constructors do not have return types, but all other methods do (T/F).

True

16
New cards

A class can include only one constructor (T/F).

False

17
New cards

A method can only have one return statement (T/F).

False

18
New cards

The OR operand evaluates to false if one operand is false (T/F).

False

19
New cards

Nested if statements offer an alternative to deal with a programs logical complexity (T/F).

True

20
New cards

Java uses complete evaluation, in which all parts of a Boolean expression are always evaluated (T/F).

False

21
New cards

Consider the following code segment:
int x = 7;
int y = 3;
if ( (x<10) && (y<0) )
System.out.println("Value is: " +x*y);
else
System.out.println("Value is: " + x/y);

Value is: 2

22
New cards

Assume that a and b have been defined and initialized as int values. The expression
!(! (a!=b) && (b>7))
is equivalent to which of the following?

(a != b) || (b <= 7)

23
New cards

Consider the following code segment.
int sum = 0;
int k =1;
while (sum < 12 || k<4)
sum += k;
System.out.println(sum);
What is printed as a result of executing the code segment?

Nothing is printed due to an infinite loop.

24
New cards

Consider the following code segment.
int num = 2574;
int result = 0;
while (num > 0) {
result = result * 10 + num % 10;
num /= 10;
}
System.out.println(result);
What is printed as a result of executing the code segment?

4752

25
New cards

Consider the following method.
public void test (int x) {
int y;
if (x % 2 ==0)
y=3;
else if (x>9)
y=5;
else
y = 1;
System.out.println("y = " + y);
}
Which of the following test data sets would test each possible output for the method?

8, 9, 11

26
New cards

Which of the following statements will result in a syntax error?

Integer x = "123";

27
New cards

What is the result when the following code segment is compiled and executed?
int m =4, n = 5;
double d = Math.sqrt( (m + n)/2);
System.out.println(d);

2.0

28
New cards

Given that x is true, y is true, and z is false, which of the following expressions will evaluate to false?
a. (X&&Y) || Z
b. (X || Y) && Z
c. Y || (X && Z)
d. X || (Y && Z)
e. X && (Y || Z)

b. (X || Y) && Z

29
New cards

What is the output of the following program segment?
int sum = 0, d= -1;
for (int count = 10; count >0; count--)
{
sum +=d;
if (d > 0)
d++;
else
d--;
d = -d;
}
System.out.println(sum);

5

30
New cards

What is the output of the following program segment?
int num = 5;
while (num >= 0)
{
num -= 2;
}
System.out.prinln(num);

-1

31
New cards

The following code segment is supposed to calculate and display 1 + 2 + ... + 20:
int count = 0, sum = 0;
while (count <20)
{
sum += count;
}
System.out.println(sum);
Which statement best displayed describes the result:
a. The total displayed will be correct.
b. The total displayed will be 20 too small.
c. The output will be the number 0.
d. The output will be the number 20.
e. There will be no output because the program goes into an infinite loop.

e. There will be no output because the program goes into an infinite loop.

32
New cards

What is the output of the following program segment?
int a = 3;
int b = 4;
int c = 0;
if ( a==b && b/c == 1)
{
c = a*b;
}
else
{
c = a + b*c;
System.out.println(c);
}

3

33
New cards

Which of the following statements about constructors are NOT true?
a. All constructors must have the same name as the class they are in
b. Constructors' return type must be declared void
c. a class may have a constructor that takes no parameters
d. a constructor is invoked when a program creates an object with the new keyword
e. Constructors should not have a return type

b. Constructors' return type must be declared void

34
New cards

110 base 2 is equivalent to what base 10 number?

6

35
New cards

A byte's location in memory is called its:

address

36
New cards

What defines or describes a list of data resources and rules of behavior?

class

37
New cards

In Object Oriented Programming objects work together by asking each other for services by
sending what to each other?

messages

38
New cards

When different types of objects respond to the same message differently, it is referred to as:

polymorphism

39
New cards

Combining the description of resources and behaviors into a single software entity is called:

encapsulation

40
New cards

The Java compiler translates Java source code into:

Java byte code

41
New cards

To run Java byte code on a particular computer you must install what on that computer?

Java Virtual Machine

42
New cards

What is the name of an object that knows how to display or print characters in a terminal
window?

System.out

43
New cards

What character is the method selector operator in Java?

period ( . )

44
New cards

What are the three steps to entering a program into a computer and running it?

Edit, Compile, Execute

45
New cards

The statement telling the Java compiler where to find a complete specification of a class is:

import

46
New cards

The Java compiler will ignore everything after what symbol?

//

47
New cards

What is the Java mechanism for repeating a group of statements?

for loop

48
New cards

What is the set of all the words and symbols in the Java programming language?

Vocabulary

49
New cards

Which of the following is NOT a primitive data type in Java?

string

50
New cards

How many numeric data types does Java include?

6

51
New cards

Which keyword in Java declares a variable whose value cannot change?

final

52
New cards

What is the string concatenation operator?

+

53
New cards

Which of the following is the escape sequence for a newline?

\n

54
New cards

What keyword indicates a method does not return a value?

void

55
New cards

Which of the following user-defined symbols is invalid?

9innings

56
New cards

In the statement import x.y.z; what does the x represent?

the name of the overall package

57
New cards

Using the same name for two different methods is called:

overloading

58
New cards

Which of the following methods is NOT included in the Math class?

readInt

59
New cards

Which of the following values could be returned from Random.nextInt(10)?

7

60
New cards

What type of expression returns either true or false?

Boolean

61
New cards

Which statement provides a looping mechanism that executes statements repeatedly as long as some condition is true?

while

62
New cards

How many times will the following loop execute?
int counter = 2;
while ( counter < 10 ){
counter += 2;

4

63
New cards

Which statement allows a loop to terminate before the loop condition is false?

break

64
New cards

The process of creating a new object is called:

instantiation

65
New cards

Java deletes objects from memory in a process called:

garbage collection

66
New cards

Which characteristic of an object says that at any moment its instance variables have particular values.

state

67
New cards

What is the list of the methods supported by the server referred to as?

interface

68
New cards

Messages that change an object's state are called:

mutators

69
New cards

What is the name of a method that indicates how to initialize a new object?

constructor

70
New cards

What are activated when the keyword new is used and at no other time.

constructors

71
New cards

A method whose implementing code is omitted is called a:

stub

72
New cards

The ________ of a variable is that region of the program within which it can validly appear in lines of code.

scope

73
New cards

The _________ of a variable is the period during which it can be used.

lifetime

74
New cards

If the operator AND is used, which of the following will make the whole condition true?

both operands true

75
New cards

Which of the following is the Java symbol for logical AND?

&&

76
New cards

A program that tolerates errors in user inputs and recovers gracefully is:

robust

77
New cards

In general, how many combinations of true and false are there for n operands in a truth table.

2^n

78
New cards

What is the symbol for the NOT operator in Java?

!

79
New cards

Which of the following Boolean expressions is equivalent to: !( p && q )

!p || !q

80
New cards

The approach in which evaluation of a Boolean expression stop as soon as possible is called:

short-circuit evaluation