Programming self Quiz unit 1 2 3 sample 1 PDF

Title Programming self Quiz unit 1 2 3 sample 1
Author Kute Face
Course Programming 1
Institution University of the People
Pages 19
File Size 451.9 KB
File Type PDF
Total Downloads 30
Total Views 143

Summary

Programming_self_Quiz_unit_1_2_3 sample 1...


Description

1.Which of the following is NOT a valid identifier in Java? Select one: a. p b. Public c. public d. public23 e. PuBlIc_tWeNtY_3 Question 2 What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte code in ".class" files into machine language c. Translates source code in ".class" files into machine language d. Translates source code in ".java" files into Java byte code in ".class" files e. Translates source code in ".java" files into machine language Feedback Your answer is incorrect. The correct answer is: Translates source code in ".java" files into Java byte code in ".class" files Question 3 Consider the following line of Java code. System.out.println("Hello, World!"); The full line of code is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

Question 4 Consider the following line of Java code. System.out.println("Hello, World!"); Which one of the following does NOT describe '"Hello, World!"'? Select one: a. a declaration b. an expression

c. a literal d. a parameter e. a statement Question 5 Consider the following line of Java code. System.out.println("Hello, World!"); "System" is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement

6. Consider the following Java program:

1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6} What is on line 1? Select one: a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition Feedback Your answer is correct. See Section 2.1 of Eck (2014). The correct answers are: a variable declaration, a class definition Question 2 Consider the following Java statements. int x = 3; x = x++; Select one:

a. 0 b. 3 c. 4 d. 5 e. The question is moot. The statements have a syntax error. Question 3 Which of the following should be used to compare the contents of two String objects in Java? Select one: a. = b. == c. cmp d. equals e. ? Feedback Your answer is incorrect. "=" is for assignment. "==" compares the memory locations of String objects, not their contents. "cmp" is a command from Python, not Java. "?" Is the conditional operator. Use "s1.equals(s2)" to compare the contents of String "s1" and "s2". See Section 2.3.3 of Eck (2014). The correct answer is: equals Question 4 Which of the following is NOT a valid identifier in Java? Select one: a. p b. Public c. public d. public23 e. PuBlIc_tWeNtY_3 Question 5 What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte code in ".class" files into machine language c. Translates source code in ".class" files into machine language d. Translates source code in ".java" files into Java byte code in ".class" files

e. Translates source code in ".java" files into machine language

Question 1 Consider the following Java statements. int x = 3; x = x++; Select one: a. 0 b. 3 c. 4 d. 5 e. The question is moot. The statements have a syntax error. Question 2 Consider the following line of Java code. System.out.println("Hello, World!"); Which one of the following does NOT describe '"Hello, World!"'? Select one: a. a declaration b. an expression c. a literal d. a parameter e. a statement Feedback '"Hello, World!"' is a String literal, which means it is also a String expression. It is the parameter to the method "println". It is not a declaration statement. See Sections 2.2.4 and 2.2.5 of Eck (2014). Question 3 Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6} What is on line 1? Select one: a. a variable declaration b. a statement c. a method (subroutine) definition

d. a comment e. a class definition Feedback Your answer is correct. See Section 2.1 of Eck (2014). The correct answers are: a variable declaration, a class definition Question 4 Which of the following should be used to compare the contents of two String objects in Java? Select one: a. = b. == c. cmp d. equals e. ? Feedback Your answer is correct. "=" is for assignment. "==" compares the memory locations of String objects, not their contents. "cmp" is a command from Python, not Java. "?" Is the conditional operator. Use "s1.equals(s2)" to compare the contents of String "s1" and "s2". See Section 2.3.3 of Eck (2014). The correct answer is: equals Question 5 Consider the following line of Java code. System.out.println("Hello, World!"); "System" is which of the following? Select one: a. a class b. a method (subroutine) c. an object d. a parameter e. a statement Feedback Your answer is correct. "System" is a built-in Java class with static member objects, like "out". See Section 2.3.1 of Eck (2014). The correct answer is: a class

Question: In a while loop, how many times does the continuation condition run? Select one: a. At least once, at the beginning of each iteration. b. At least once, at the end of each iteration. c. Exactly once. d. Zero or more times, at the beginning of each iteration. e. Zero or more times, at the end of each iteration. Feedback Your answer is correct. See Section 3.4.1 of Eck (2014). The correct answer is: At least once, at the beginning of each iteration. Question 2 Which one of the following types is not allowed for the expression in a switch statement? Select one: a. enum b. float c. int d. long Question 3 In a do-while loop, how many times does the continuation condition run (if the loop has no break, return, or System.exit calls)? Select one: a. At least once, at the beginning of each iteration. b. At least once, at the end of each iteration. c. Exactly once. d. Zero or more times, at the beginning of each iteration. e. Zero or more times, at the end of each iteration. Feedback Your answer is correct. See Section 3.3.2 of Eck (2014). The correct answer is: At least once, at the end of each iteration.

Question 4 Consider the following block of Java code. How many times will it output "Hello"? for (int i = 1; i < 10; i++) { System.out.println("Hello"); } Select one: a. 0 b. 9 c. 1 d. 10 e. Way too many! Feedback Your answer is correct. Notice that the condition is "i < 10", not "i...


Similar Free PDFs