AP Computer Science Final Exam

studied byStudied by 0 people
0.0(0)
Get a hint
Hint

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

1 / 79

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

80 Terms

1

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

True

New cards
2

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

False

New cards
3

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

True

New cards
4

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

False

New cards
5

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

True

New cards
6

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

False

New cards
7

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

False

New cards
8

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

False

New cards
9

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

False

New cards
10

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

True

New cards
11

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

False

New cards
12

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

False

New cards
13

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

True

New cards
14

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

True

New cards
15

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

True

New cards
16

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

False

New cards
17

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

False

New cards
18

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

False

New cards
19

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

True

New cards
20

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

False

New cards
21

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

New cards
22

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)

New cards
23

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.

New cards
24

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

New cards
25

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

New cards
26

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

Integer x = "123";

New cards
27

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

New cards
28

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

New cards
29

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

New cards
30

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

-1

New cards
31

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.

New cards
32

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

New cards
33

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

New cards
34

110 base 2 is equivalent to what base 10 number?

6

New cards
35

A byte's location in memory is called its:

address

New cards
36

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

class

New cards
37

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

messages

New cards
38

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

polymorphism

New cards
39

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

encapsulation

New cards
40

The Java compiler translates Java source code into:

Java byte code

New cards
41

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

Java Virtual Machine

New cards
42

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

System.out

New cards
43

What character is the method selector operator in Java?

period ( . )

New cards
44

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

Edit, Compile, Execute

New cards
45

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

import

New cards
46

The Java compiler will ignore everything after what symbol?

//

New cards
47

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

for loop

New cards
48

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

Vocabulary

New cards
49

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

string

New cards
50

How many numeric data types does Java include?

6

New cards
51

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

final

New cards
52

What is the string concatenation operator?

+

New cards
53

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

\n

New cards
54

What keyword indicates a method does not return a value?

void

New cards
55

Which of the following user-defined symbols is invalid?

9innings

New cards
56

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

the name of the overall package

New cards
57

Using the same name for two different methods is called:

overloading

New cards
58

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

readInt

New cards
59

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

7

New cards
60

What type of expression returns either true or false?

Boolean

New cards
61

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

while

New cards
62

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

4

New cards
63

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

break

New cards
64

The process of creating a new object is called:

instantiation

New cards
65

Java deletes objects from memory in a process called:

garbage collection

New cards
66

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

state

New cards
67

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

interface

New cards
68

Messages that change an object's state are called:

mutators

New cards
69

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

constructor

New cards
70

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

constructors

New cards
71

A method whose implementing code is omitted is called a:

stub

New cards
72

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

scope

New cards
73

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

lifetime

New cards
74

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

both operands true

New cards
75

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

&&

New cards
76

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

robust

New cards
77

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

2^n

New cards
78

What is the symbol for the NOT operator in Java?

!

New cards
79

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

!p || !q

New cards
80

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

short-circuit evaluation

New cards

Explore top notes

note Note
studied byStudied by 10 people
... ago
5.0(1)
note Note
studied byStudied by 5 people
... ago
5.0(1)
note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 18 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 3250 people
... ago
4.7(18)
note Note
studied byStudied by 5 people
... ago
5.0(1)
note Note
studied byStudied by 26 people
... ago
5.0(1)

Explore top flashcards

flashcards Flashcard (27)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (322)
studied byStudied by 314 people
... ago
5.0(1)
flashcards Flashcard (35)
studied byStudied by 12 people
... ago
5.0(1)
flashcards Flashcard (47)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (45)
studied byStudied by 96 people
... ago
5.0(4)
flashcards Flashcard (78)
studied byStudied by 34 people
... ago
5.0(1)
flashcards Flashcard (32)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (27)
studied byStudied by 488 people
... ago
5.0(14)
robot