Quiz 2021, questions and answers PDF

Title Quiz 2021, questions and answers
Course Programming 1
Institution University of the People
Pages 5
File Size 117.9 KB
File Type PDF
Total Downloads 34
Total Views 127

Summary

CS1102 Unit 1 Quiz...


Description

CS1102 Unit 1 Quiz Question 1: 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. ?

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 2: 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

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 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

Your answer is correct.

See Section 2.1 of Eck (2014).

The correct answer is: a statement

Question 4: 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

Your answer is correct.

The correct answer is: Translates source code in ".java" files into Java byte code in ".class" files

Question 5: Consider the following Java statements.

int x = 3;

x = x++;

What is the value x is holding?

Select one: a. 0 b. 3 c. 4 d. 5 e. The question is moot. The statements have a syntax error. Your answer is correct.

Though "x++" increments the value of "x" from 3 to 4, it returns the previous value of "3" as an expression. That value, 3, then gets assigned back to "x" with the "x =" assignment. In the end, "x" has the value it started with. See Section 2.5.2 of Eck (2014).

The correct answer is: 3









...


Similar Free PDFs