Java Chapter 2 Quiz

2041 Words Sep 29th, 2012 9 Pages
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
…show more content…
String name = “John Doe”;
a. John Doe
b. The memory address where “John Doe” is located
c. name
d. The memory address where name is located

ANS: B

22. What will be displayed as a result of executing the following code? int x = 6;
String msg = “I am enjoying this class.”;
String msg1 = msg.toUpperCase();
String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length();
System.out.println(msg);
System.out.println(msg1);
System.out.println(msg2);
System.out.println(“Character at index x = ” + ltr);
System.out.println(“msg has ” + strSize + “characters.”);
a. I am enjoying this class.
I AM ENJOYING THIS CLASS. i am enjoying this class.
Character at index x = e msg has 24 characters.
b. I am enjoying this class.
I AM ENJOYING THIS CLASS. i am enjoying this class.
Character at index x = e msg has 25 characters.
14 Gaddis • Starting Out with Java 5: From Control Structures to Objects
c. I am enjoying this class.
I AM ENJOYING THIS CLASS. i am enjoying this class.
Character at index x = n msg has 24 characters.
d. I am enjoying this class.
I AM ENJOYING THIS CLASS. i am enjoying this class.
Character at index x = n msg has 25 characters.

ANS: D

23. A variable’s scope is the part of the program that has access to the variable.
a. True
b. False

ANS: A

24. What will be displayed as a result of executing the following code? public class test
{
public static void main(String[] args) { int value1

More about Java Chapter 2 Quiz