Multiple
Choice
Identify the letter of the choice that best completes the statement or answers the
question.
|
|
|
Use the following class definition to answer questions 1-4.
public class
Questions1_4
{
public static void main(String[ ]
args)
{
System.out.print("Here");
System.out.println("There " +
"Everywhere");
System.out.println("But not" +
"in Texas");
}
}
|
|
|
1.
|
How many lines of
output are provided by this program?
|
|
|
2.
|
The final println
command will output a. | "But not+in
Texas" | d. | "But not + in
Texas" | b. | "But not
in Texas" | e. | "But not" on one line and "in Texas"
on the next line | c. | "But notin
Texas" | | | | |
|
|
|
3.
|
The program will
print the word "Here" and then print a. | "There" on the line
after "Here" and "Everywhere" on the line after
"There" | d. | "ThereEverywhere" on the line after
"Here" | b. | "There
Everywhere" on the same line as "Here" | e. | "ThereEverywhere" on
the same line as "Here" | c. | "There
Everywhere" on the line after "Here" | | | | |
|
|
|
4.
|
A reasonable comment
for this program might be a. | // a program that demonstrates
nothing at all | d. | // a program that has three output statements in
it | b. | // a program that
demonstrates the differences between print, println and how + works | e. | // a program that outputs the
message Here There Everywhere But not in Texas | c. | // a program that outputs a message about
Texas | | | | |
|
|
|
5.
|
What is output with
the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? a. | x+y | d. | 10.5 | b. | 105 | e. | An error since neither x nor y
is a String | c. | 15 | | | | |
|
|
|
6.
|
What value will z
have if we execute the following assignment statement? a. | z will equal 0.5 | d. | z will equal
5.0 | b. | z will equal
0.05 | e. | z will equal 0.05 | c. | z will equal 0.0 | | | | |
|
|
|
7.
|
A cast is required in
which of the following situations? a. | storing a double in a
double | d. | storing a double in an int | b. | using charAt to take an element of a String and store it in a
char | e. | all of the above require casts | c. | storing an int in a double | | | | |
|
|
|
8.
|
If you want to output
the text "hi there", including the quote marks, which of the following could do
that? a. | System.out.println("\"hi
there\""); | d. | System.out.println("\"hi
there\""); | b. | System.out.println("\"hi there"); | e. | System.out.println(""hi there""); | c. | System.out.println("hi there"); | | | | |
|
|
|
9.
|
What will be the result of the following assignment statement?
Assume b = 5 and c = 10.
int a = b * (-c + 2) / 2;
|
|
|
10.
|
Of the following
types, which one cannot store a numeric value? a. | char | d. | double | b. | none of these can store numeric values | e. | all of these can store numeric
values | c. | int | | | | |
|