P8 Test Questions

(Project Test Home Page)

# Question
1 Which identifiers are legal?
(Choose all that apply)

A. 1Hello
B. Hello1
C. Hello 1
D. None of the above?

2 Which identifiers are legal?
(Choose all that apply)

A. $Hello
B. Hello$1
C. 1$Hello
D. None of the above.

3 Which identifiers are legal?
(Choose all that apply)

A. 1_Hello
B. _Hello1
C. %Hello1
D. None of the above.

4 Choose the true statements about the following code.
(Choose all that apply)

System.out.println("Hello "World" Class");

A. Prints to the Java Console: Hello "World" Class
B. Prints to the Java Console: "Hello "World" Class"
C. Compile error.
D. None of the above.

5 Choose the true statements about the following code.
(Choose all that apply)

String strMsg = "My nick name is \"Mike\"\nfor Michael";
System.out.println(strMsg);

A. Prints to the Java Console on line 1: My nick name is "Mike"    for Michael
B. Compile error.
C. Creates a runtime error.
D. None of the above.

6 Choose the true statements about the following code.
(Choose all that apply)

String strMsg = "Say, \"I Love You\"\nToo";
System.out.println(strMsg);

A. Prints to the Java Console on line 1: Say, "I Love You"
B. Compile error.
C. Prints to the Java Console on line 2: Too
D. None of the above.

7 Choose all the code samples that will compile.
(Choose all that apply)

A. Boolean blnMy = true;
B. character charMy = 'A';
C. integer intMy = 1;
D. None of the above.

8 Choose all the code samples that will compile.
(Choose all that apply)

A. int intMy = 10L;
B. long lngMy = 10L;
C. int intMy = 10.0;
D. None of the above.

9 Choose all the code samples that will compile.
(Choose all that apply)

A. double dblMy = 10.0;
B. double dblMy = 10;
C. double dblMy = 10d;
D. None of the above.

10 Choose all the code samples that will compile.
(Choose all that apply)

A. char charMy = "A";
B. char charMy = 'A';
C. char charMy = 10.0D;
D. None of the above.

11 Choose all the code samples that will compile.  Assume the following code exits.
(Choose all that apply)

byte byteMy = (byte) 10;
short shtMy = (short) 10;

A. byte byteTest = byteMy;
B. byte byteTest = shtMy;
C. byte byteTest = (byte) shtMy;
D. None of the above.

12 An identifier is a series of characters consisting of letters, digits, underscores(_) and dollar signs ($) that does not begin with a digit, does not contain any spaces and is not a keyword.

True
False

13 When working with Primitive Data, you can assign a lower precision to a higher precision because Java will implicitly cast.

True
False

14 You must explicitly cast when assigning Primitive Data with a higher precision to a lower precision.

True
False

15 Choose which statements are true.  Assume the following code exits.
(Choose all that apply)

short shtMy = (short) 10;
int intMy = 10;
double dblMy = 10.0D;
float fltMy = 10.0F;

A. intMy = shtMy;
B. shtMy = intMy;
C. fltMy = (float) dblMy;
D. intMy = (int) dblMy;

16 Choose which statements are true.
(Choose all that apply)

A. There are 4 integer data types: byte, short, int, long.
B. There are 2 floating point data types: float, double.
C. The following is a complete list of Primitives: byte, short, int, long, float, double, char, boolean.
D. None of the above.

17 Choose which statements are valid method identifiers.
(Choose all that apply)

A. private void 2MyMethod () {} 
B. private void _MyMethod () {}
C. private void ?MyMethod () {}
D. private void $MyMethod () {}

18 Choose which statements are valid class identifiers.
(Choose all that apply)

A. class _MyClass{}
B. class 2MyClass {}
C. class $MyClass {}
D. class +MyClass {} 

19 Choose which statements will compile with JDK 1.2 and above.
(Choose all that apply)

A. int intMy = Integer.parseInt("10");
B. int intMy = Integer.parseInt( 10 );
C. String strMy = Integer.toString( 10 );
D. String strMy = Integer.toString( 10.0 );

20 Choose which statements will compile with JDK 1.2 and above.
(Choose all that apply)

A. double dblMy = Double.parseDouble( 10.0 );
B. double dblMy = Double.parseDouble("10.0");
C. String strMy = Double.toString( 10.0 );
D. String strMy = Double.toString( 10 );