Java Chapter 2 Test Questions and Answers|
Latest Update 100% Solved
Which of the following does not describe a valid comment in Java?
A) Single line comments, two forward slashes - //
B) Multi-line comments, start with /* and end with */
C) Multi-line comments, start with */ and end with /*
D) Documentation comments, any comments starting with /** and ending with */ ✔️✔️C) multi-
line comments, start with */ and end with /*
Which of the following statements correctly creates a Scanner object for keyboard input?
A) Scanner kbd = new Scanner(System.keyboard);
B) Scanner keyboard(System.in);
C) Scanner keyboard = new Scanner(System.in);
D) Keyboard scanner = new Keyboard(System.in); ✔️✔️C) Scanner keyboard= new
Scanner(System.in);
Which Scanner class method reads an int?
A) readInt()
B) nextInt()
C) getInt()
D) read_int() ✔️✔️B) nextInt()
Which Scanner class method reads a String?
A) readString()
B) nextString()
C) getString()
, D) nextLine() ✔️✔️D) nextLine()
Which one of the following methods would you use to convert a string to a double?
A) Byte.ParseByte
B) Long.ParseLong
C) Integer.ParseInt
D) Double.ParseDouble ✔️✔️D) Double.ParseDouble
T/F:A Java program will not compile unless it contains the correct line numbers. ✔️✔️FALSE
T/F: All Java statements end with semicolons. ✔️✔️FALSE
T/F: Java is a case-insensitive language. ✔️✔️FALSE
T/F: Although the dollar sign is a legal identifier character, you should not use it because it is
normally used
for special purposes. ✔️✔️TRUE
T/F: Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44; ✔️✔️FALSE
T/F: Named constants are initialized with a value, that value cannot be changed during the
execution of the
program. ✔️✔️TRUE
T/F: A variable's scope is the part of the program that has access to the variable. ✔️✔️TRUE
Latest Update 100% Solved
Which of the following does not describe a valid comment in Java?
A) Single line comments, two forward slashes - //
B) Multi-line comments, start with /* and end with */
C) Multi-line comments, start with */ and end with /*
D) Documentation comments, any comments starting with /** and ending with */ ✔️✔️C) multi-
line comments, start with */ and end with /*
Which of the following statements correctly creates a Scanner object for keyboard input?
A) Scanner kbd = new Scanner(System.keyboard);
B) Scanner keyboard(System.in);
C) Scanner keyboard = new Scanner(System.in);
D) Keyboard scanner = new Keyboard(System.in); ✔️✔️C) Scanner keyboard= new
Scanner(System.in);
Which Scanner class method reads an int?
A) readInt()
B) nextInt()
C) getInt()
D) read_int() ✔️✔️B) nextInt()
Which Scanner class method reads a String?
A) readString()
B) nextString()
C) getString()
, D) nextLine() ✔️✔️D) nextLine()
Which one of the following methods would you use to convert a string to a double?
A) Byte.ParseByte
B) Long.ParseLong
C) Integer.ParseInt
D) Double.ParseDouble ✔️✔️D) Double.ParseDouble
T/F:A Java program will not compile unless it contains the correct line numbers. ✔️✔️FALSE
T/F: All Java statements end with semicolons. ✔️✔️FALSE
T/F: Java is a case-insensitive language. ✔️✔️FALSE
T/F: Although the dollar sign is a legal identifier character, you should not use it because it is
normally used
for special purposes. ✔️✔️TRUE
T/F: Assuming that pay has been declared a double, the following statement is valid.
pay = 2,583.44; ✔️✔️FALSE
T/F: Named constants are initialized with a value, that value cannot be changed during the
execution of the
program. ✔️✔️TRUE
T/F: A variable's scope is the part of the program that has access to the variable. ✔️✔️TRUE