Chapter 02 – Java Fundamentals
Multiple Choice
1. To compile a program named, First, use the following command
a. java-source 1.5 First.java
b. javac-source 1.5 First
c. javac First.java
d. compile First.javac
ANS: C
2. A Java program must have at least one
a. Class definition
b. Variable
c. Comment
d. System.out.println(); statement
ANS: A
3. All Java lines of code end with semicolons.
a. True
b. False
ANS: A
4. The ____ is normally considered the standard output and standard input devices, and usually refer to the monitor and keyboard.
a. CRT
b. CPU
c. secondary storage devices
d. console
ANS: D
5. If the following Java statements are executed, what will be displayed
System.out.println(“The top three winners are\n”);
System.out.print(“Jody, the Giant\n”);
System.out.print(“Buffy, the Dwarf”);
System.out.println(“Adelle, the Albino”);
a. The top three winners are
Jody, the Giant
Buffy, the Dwarf
Adelle, the Albino
b. The top three winners are
Jody, the Giant\nBuffy, the DwarfAdelle, the Albino
c. The top three winners are Jody, the Giant\nBuffy, the DwarfAdelle, and the Albino
d. The top three winners are
Jody, the Giant
Buffy, the DwarfAdelle, the Albino
ANS: D
6. A(n) ____ is a value that is written into the code of a program.
a. literal
b. assignment statement
c. variable
d. operator
ANS: A
7. What would be printed out as a result of the following code?
System.out.println(“The quick brown fox”
+ “jumped over the \n”
“slow moving hen.”);
a. The quick brown fox jumped over the \nslow moving hen.
b. The quick brown fox jumped over the slow moving hen.
c. The quick brown fox jumped over the slow moving hen.
d. Nothing. This is an error.
ANS: D
8. Which of the following is not a rule that must be followed when naming identifiers?
a. The first character must be one of the letters a–z, A–Z, and underscore or a dollar sign.
b. Identifiers can contain spaces.
c. Uppercase and