Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CS 241 Practice Test Week 2

Total questions: 61

Worksheet time: 2hrs 44mins

Name
Class
Date
1.

What type of error will this cause, where there should be a semicolon at the end of this Java command?

String name = "Joe

a)

Syntax Error

b)

Lexical

c)

Run-time Error

d)

Logic Error

2.

The Java code segment below has been saved in a file called "JollyMessage.java". What type of error, if any, will occur?

a)

Syntax

b)

Run-time

c)

Logic

d)

Lexical

e)

No Error

3.

Errors that occur during the execution of a program happen in ___________ _________.

a)

run time

b)

compile time

4.

Arranging commands in a programming statement not in the required order is a ______________ error.

a)

syntax

b)

logic

c)

runtime

d)

lexical

5.

In some languages, forgetting to end a statement with a semicolon is a ______________ error.

a)

logic

b)

runtime

c)

syntax

d)

lexical

6.

Syntax errors occur during ___________ _________.

a)

run time

b)

compile time

7.

Logic errors occur during ___________ _________.

a)

run time

b)

compile time

8.

Leaving out a required closing brace, bracket, or parentheses is a ______________ error.

a)

Lexical

b)

Syntax

c)

Runtime

d)

Logic

9.

Lexical errors occur during ___________ _________.

a)

compile time

b)

runtime

10.

What part of the method is highlighted here?

a)

header

b)

method call

c)

body

d)

return type

11.

what part of the method is highlighted here?

a)

header

b)

return type

c)

method name

d)

parameter list

12.

What part of the method is highlighted here?

a)

method name

b)

header

c)

return type

d)

method call

13.

What part of the method is highlighted here?

a)

method end

b)

parameter list

c)

method name

d)

return type

14.

What part of the method is highlighted here?

a)

method name

b)

method parameters

c)

method type

d)

return method

15.

What part of the method is highlighted here?

a)

return type

b)

parameter list

c)

method name

d)

method end

16.

The block of code that makes up the process performed by a procedure, function, or method.

a)

definition/body

b)

parameter list

c)

header

d)

call

17.

A statement that activates or executes a procedure, function, or method.

a)

call

b)

header

c)

parameter list

d)

definition/body

18.

A block of code that performs an action without returning a value.

a)

function

b)

method call

c)

return method

d)

procedure

19.

The first line of a procedure, function, or method.

a)

definition/body

b)

parameter list

c)

header

d)

call

20.

A variable in the parameter list of a method header.

a)

Reference parameter

b)

Value parameter

c)

Formal parameter

d)

Actual parameter

21.

A value, variable, or expression in the parameter list of a method call.

a)

Reference Parameter

b)

Actual Parameter

c)

Value Parameter

d)

Formal Parameter

22.

The type of parameter where changes by the method DO NOT affect the original data.

a)

Formal Parameter

b)

Value Parameter

c)

Actual Parameter

d)

Reference Parameter

23.

In the pseudocode example shown, "Suzy" is an example of a(an) ______________ parameter

a)

Actual

b)

Formal

c)

Value

d)

Reference

24.

A programming block of code that performs a calculation and sends back the result of that calculation.

a)

Function or return method

b)

Definition

c)

Header

d)

Procedure, void method

e)

Call

25.

What is printed by the code segment shown below?

a)

16

b)

22

c)

42

d)

64

e)

48

26.

What is output the code segment shown below?

a)

5*4

b)

20

c)

1

d)

5,4

27.

What is output by the code segment shown below?

a)

48 48

b)

48 12

c)

12 48

d)

12 12

28.

What is output by the code segment shown below?

a)

16 5 16

b)

16 5 5

c)

16 7 16

d)

16 7 7

29.

What is the output by the code segment shown below?

a)

No ouput

b)

x+y

c)

11

d)

5+6

30.

What is output by the code segment shown below?

a)

11

b)

4+7

c)

9+9

d)

18

31.

What is output by the code segment shown below?

a)

2272

b)

2777

c)

2277

d)

7722

32.

What is output by the code segment shown below?

a)

2-2:2:10:10:10-

b)

2-2:2:7:10:10-

c)

2-2:2:7:5:2-

d)

2-2:2:7:10:2-

33.

Consider the following method:

What is returned by the method call sum(7,6)

a)

13

b)

7

c)

Nothing

d)

7+6

34.

Consider the following method. What is is printed by the method call sum(8,10) ?

a)

8+10

b)

2

c)

18

d)

10-8

35.
a)

4

b)

14

c)

9 5

d)

5 9

36.

Consider the following method. What is returned by the method call f(30)?

a)

Large

b)

Small

c)

Nothing is printed

d)

LargeSmall

37.

Consider the following method. What is output by the method call: print greetTheDay(14)

a)

Good day

b)

Good evening

c)

Good monring

d)

nothing

38.

What is output of this code segment?

a)

1

b)

0

c)

17

d)

35

39.

What is printed?

a)

WednesdayThursdayFridaySaturday

b)

Sunday

c)

Tuesday

d)

Saturday

40.

What is printed?

a)

Sunday

b)

Saturday

c)

WednesdayThursdayFridaySaturday

d)

Tuesday

41.

What is printed?

a)

"Poorly done. You can do better!"

b)

"An very good grade!"

c)

"This isn't a grade!"

d)

"Very average."

42.

What is printed?

a)

Mangoes and papayas are $2.79 a pound."

b)

"Bananas are $0.48 a pound."

c)

"Oranges are $0.59 a pound."

d)

"Sorry, we're out of Mangoes"

43.

Which of these reserved words is NOT used to control a switch statement?

a)

case

b)

continue

c)

default

d)

switch

e)

break

44.

The switch statement below should calculate a week's pay based on number of years experience. For 1 year of experience, the hourly wage is $7, for 2 years $8 an hour, 3 years $10, 4 years $12, and 5 years $15 per hour. The number of hours will vary between 1 and 40 hours. Which choice will be used to correctly calculate the totalWeekPay so that the output shown is $200?

a)

case 1: totalWeekPay = hours*7;break;

b)

case 4: totalWeekPay = hours*15;break;

c)

case 3: totalWeekPay = hours*10;break;

d)

case 2: totalWeekPay = hours*8;break;

e)

case 3: totalWeekPay = hours*12;break;

45.

What is printed?

a)

"default"

b)

"Buzz"

c)

"FizzBuzz"

d)

"Fizz"

46.

Which choice represents a program feature that activates a predefined block of code?

a)

Method header

b)

Return method or function

c)

Method Definition

d)

Void Method or procedure

e)

Method call

47.

When a program executes just fine, but the outcome is incorrect, this is a classified as a ______________ error.

a)

logic

b)

runtime

c)

syntax

d)

lexical

48.

Which of the following are considered good program debugging strategies? Check all that apply.

a)

Intentionally use bad data to see if your program can handle it.

b)

Look at the arrows in the compiler generated error messages to locate the error.

c)

Hide portions of the program that don't seem to work and "unhide" them one at a time until the offending line is discovered.

d)

Read the error messages provided by the compiler.

49.

Which choice describes a programming block of code that produces a calculated value?

a)

method header

b)

method definition

c)

return method or function

d)

void method or procedure

e)

method call

50.

In this pseudocode example, String name is an example of a(an) __________ parameter.

a)

Formal

b)

Reference

c)

Actual

d)

Value

51.

Not capitalizing a reserved word that should be capitalized in a programming statement is a ______________ error.

a)

Runtime

b)

Logic

c)

Syntax

d)

Lexical

52.

Which choices represent the possible operators correctly filling the blank resulting in an output value of 14? Check all that apply.

a)

==

b)

≤\le

c)

≠\ne

d)

<<

e)

≥\ge

53.

Forgetting to end a string with a double quote symbol is a ______________ error.

a)

Logic

b)

Runtime

c)

Lexcial

d)

Syntax

54.

During the execution of a program, entering a String when an integer is expected is an example of a ______________ error.

a)

Runtime

b)

Lexcial

c)

Logic

d)

Syntax

55.

What is printed?

(a)  

56.

A switch statement is useful when your program logic contains a chain of ______.

a)

if else statements

b)

variable declarations

c)

method calls

d)

parameters

e)

loops

57.

The type of parameter where changes by the method DO affect the original data.

a)

Formal parameter

b)

Value parameter

c)

Actual parameter

d)

Reference parameter

58.

What is printed?

(a)  

59.

Select the choice representing the final value of this Boolean expression.

TRUE AND FALSE OR TRUE XOR FALSE

a)

True

b)

False

60.

What is printed?

(a)  

61.

Which choice shows the correct parameter signature for the doStuff method header based on the final output shown below?

a)

passed_by_reference int x, passed_by_reference y

b)

passed_by_reference int x, passed_by_value y

c)

passed_by_value int x, passed_by_value y

d)

passed_by_value int x, passed_by_reference y