Java Chapter 2 Quiz

Only available on StudyMode
  • Topic: Java, Class, C++
  • Pages : 15 (2047 words )
  • Download(s) : 1630
  • Published : October 5, 2012
Open Document
Text Preview
Gaddis – Starting Out With Java 5 – From Control Structures to Objects 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 lowercase characters are distinct.
d.After the first character, you may use the letters a–z, A–Z, the underscore, a dollar sign, or digits 0–9.

ANS: B

9. Although the dollar sign, $, is a legal identifier character, you should not use it because it is normally used for special purposes. a.True
b.False

ANS: A

10. Which of the following is not a primitive data type?
a.short
b.long
c.float
d.String

ANS: D

11. Which of the following is valid?
a.float y;
y = 54.9;
b.float y;
double z;
z = 934.21;
y = z;
c.float w;
w = 1.0f;
d.double v;
v = 1.0f;

ANS: C

12. Assuming that pay has been declared a double, double pay, the following statement is valid. pay = 2,583.44;
a.True
b.False

ANS: B

13. The boolean data type may contain values in the following range of values a.True/False
b.–128 to +127
c.–2,147,483,648 to +2,147,483,647
d.–32,768 to +32,767

ANS: A

14. Character literals are enclosed in _____; string literals are enclosed in _____. a.single quotes; single quotes
b.double quotes; double quotes
c.single quotes; double quotes
d.double quotes; single quotes

ANS: C

15. What is the result of the following statement?
10 + 5 * 3 – 20
a.–5
b.5
c.25
d.–50

ANS: B

16. What is the result of the following statement?
25/4 + 4 * 10 % 3
a.19
b.5.25
c.3
d.7

ANS: D

17. Which of the following will correctly convert the data type, if x is an integer and y is a double? a.x = y;
b.x = int y;
c.x = (int)y;
d.x = y;

ANS: C

18. What will be displayed as a result of executing the following code? int x = 5, y = 20;
x *= y;
y% =x;
System.out.println(“x = ” + x + “, y = ” + y);
a.x = 5, y = 20
b.x = 25, y = 4
c.x = 100, y = 0
d.x = 100, y = 20

ANS: D

19. Named constants are initialized with a value, that value cannot be changed during the execution of the program. a.True
b.False...
tracking img