WorksheetsAP CS Test 0 Module 1
Total questions: 17
Worksheet time: 20mins
1. Consider the following code segment.
System.out.println("\"This is my output.\"");
This is my output.
"This is my output."
"\"This is my output.\""
\"This is my output.\"
Nothing, it will produce an error.
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();
}
}
I only
II only
III only
I and II
I, II and III
What is a static method?
a named group of statements
a single word in a program
the names of classes, methods, variables
a sequence of characters
what is the difference between print and println
print() prints the given content & println() prints the given content on a new line
There is no difference
print() prints the given content on a new line & printn() prints the given content
defines and declares to print the program using a printer
Consider the following Java statement.
System.out.println(" Hello World ")
Which of the following is true about this Java statement?
The statement contains a String literal that is missing a quotation mark " at its end.
The statement is missing a semicolon
The statement uses incorrect capitalization (uppercase / lowercase)
The statement uses braces [ ] instead of parentheses ( )
There are no errors in this statement.
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?
The statement contains a String literal that is missing a quotation mark " at its end.
The statement is missing a semicolon
The statement uses incorrect capitalization (uppercase / lowercase)
The statement uses braces [ ] instead of parentheses ( )
There are no errors in this statement.
Which of the following is correct
public class MyFile {
Public class MyFile {
public Class MyFile {
Identify the string in
System.out.println(“Hello World”);
Hello World
System.out
println
(" ")
Which of the following is NOT an escape sequence?
\n
/n
\\
//
Syntax errors include
misspelled words
forgotten semicolons
missing words
there is no such thing as a "syntax error"
__________ errors occur when a bug causes your computer to be unable to continue executing.
runtime error
syntax error
error error
java error
Why is it useful to comment on your code?
helps a reader understand what’s going on
comments allows your program to run smoothly
you are unable to comment on codes
comments are needed for syntax errors
What is true about Identifiers from the following:
Identifiers are always have spaces between them.
Identifiers are always a single word.
are the names of classes, methods, variables, etc
myVariableIsSuperLongButIDontCare is a good example of a proper identifier
True or False:
When using static methods, you should define/declare the method and call (or run) the method.
True
False
The body of a method definition is contained within a set of ______________.
parentheses
rectangle brackets
curly braces
angle brackets
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.
void
static
public
boolean
