wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CS Test 0 Module 1

Total questions: 17

Worksheet time: 20mins

Name
Class
Date
1.

1. Consider the following code segment.


System.out.println("\"This is my output.\"");

a)

This is my output.

b)

"This is my output."

c)

"\"This is my output.\""

d)

\"This is my output.\"

e)

Nothing, it will produce an error.

2.

A teacher asks the class to write Java program that produces the following output:


fee fi fo fum


Which of the following complete programs correctly produces this output?


I. public class MyClass {

public static void main(String[] args) {

System.out.println("fee fi fo fum");

}

}


II. public class MyClass {

public static void foFum() {

System.out.println("fo fum");

}

public static void feeFi() {

System.out.print("fee fi ");

}

public static void main(String[] args) {

feeFi();

foFum();

}

}


III. public class MyClass {

public static void feeFi() {

System.out.print("fee fi ");

foFum();

}

public static void foFum() {

System.out.println("fo fum");

}

public static void main(String[] args) {

feeFi();

}

}

a)

I only

b)

II only

c)

III only

d)

I and II

e)

I, II and III

3.

What is a static method?

a)

a named group of statements

b)

a single word in a program

c)

the names of classes, methods, variables

d)

a sequence of characters

4.

what is the difference between print and println

a)

print() prints the given content & println() prints the given content on a new line

b)

There is no difference

c)

print() prints the given content on a new line & printn() prints the given content

d)

defines and declares to print the program using a printer

5.

Consider the following Java statement.


System.out.println(" Hello World ")


Which of the following is true about this Java statement?

a)

The statement contains a String literal that is missing a quotation mark " at its end.

b)

The statement is missing a semicolon

c)

The statement uses incorrect capitalization (uppercase / lowercase)

d)

The statement uses braces [ ] instead of parentheses ( )

e)

There are no errors in this statement.

6.

Consider the following Java statement.


system.out.println("Don't forget to study for your exam);


Which of the following is true about this Java statement?

a)

The statement contains a String literal that is missing a quotation mark " at its end.

b)

The statement is missing a semicolon

c)

The statement uses incorrect capitalization (uppercase / lowercase)

d)

The statement uses braces [ ] instead of parentheses ( )

e)

There are no errors in this statement.

7.

Which of the following is correct

a)

public class MyFile {

b)

Public class MyFile {

c)

public Class MyFile {

8.

Identify the string in


System.out.println(“Hello World”);

a)

Hello World

b)

System.out

c)

println

d)

(" ")

9.

Which of the following is NOT an escape sequence?

a)

\n

b)

/n

c)

\\

d)

//

10.

Syntax errors include

a)

misspelled words

b)

forgotten semicolons

c)

missing words

d)

there is no such thing as a "syntax error"

11.

__________ errors occur when a bug causes your computer to be unable to continue executing.

a)

runtime error

b)

syntax error

c)

error error

d)

java error

12.

Why is it useful to comment on your code?

a)

helps a reader understand what’s going on

b)

comments allows your program to run smoothly

c)

you are unable to comment on codes

d)

comments are needed for syntax errors

13.

What is true about Identifiers from the following:

a)

Identifiers are always have spaces between them.

b)

Identifiers are always a single word.

c)

are the names of classes, methods, variables, etc

d)

myVariableIsSuperLongButIDontCare is a good example of a proper identifier

14.

True or False:


When using static methods, you should define/declare the method and call (or run) the method.

a)

True

b)

False

15.
________ methods are accessible to all classes and client programs.
a)
a. private
b)
b. public
c)
c. setter
d)
d. getter
16.

The body of a method definition is contained within a set of ______________.

a)

parentheses

b)

rectangle brackets

c)

curly braces

d)

angle brackets

17.

Methods that contain the _______ keyword in the data type position do not return any data, so they can simply be called without being part of a larger statement.

a)

void

b)

static

c)

public

d)

boolean