0% found this document useful (0 votes)
19 views32 pages

Review Quiz - Attempt Review Cs1102

The document provides a detailed review of a quiz taken by a student in a Java programming course, including the questions, answers, and explanations for each question. The student completed the quiz with a score of 77.14 out of 100, answering 27 out of 35 questions correctly. The document highlights both correct and incorrect responses, along with relevant sections from the course material for further reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views32 pages

Review Quiz - Attempt Review Cs1102

The document provides a detailed review of a quiz taken by a student in a Java programming course, including the questions, answers, and explanations for each question. The student completed the quiz with a score of 77.14 out of 100, answering 27 out of 35 questions correctly. The document highlights both correct and incorrect responses, along with relevant sections from the course material for further reference.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

8/10/22, 6:21 PM Review Quiz: Attempt review

Dashboard / My courses / CS 1102-01 - AY2022-T5 / Final Exam (Days 1 - 4) / Review Quiz

Started on Monday, 8 August 2022, 6:53 AM


State Finished
Completed on Monday, 8 August 2022, 7:15 AM
Time taken 21 mins 55 secs
Marks 27.00/35.00
Grade 77.14 out of 100.00

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 1/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 1

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

class Food {
Food() { printFlavor(); }
void printFlavor() { System.out.println("bland"); }
}
class Pepper extends Food {
void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food lunch = new Pepper();
}
}

Select one:
a. bland

b. bland
spicy

c. no output

d. spicy 

e. the program does not compile

Your answer is correct.


The compiler automatically calls the "Food" constructor, which calls the method "printFlavor". Unlike constructors, methods ARE
polymorphic. Because the "Pepper" class overrides the "printFlavor" method, that is the one that gets called by the "Food" constructor
for the "Pepper" object. See Sections 5.5.4 and 5.6.3.
The correct answer is: spicy

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 2/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 2

Correct

Mark 1.00 out of 1.00

Which one of the following is an event handler?

Select one:
a. an event generator

b. an event listener 

c. an event loop

d. an event method

e. javafx.scene.input.MouseEvent;

Your answer is correct.


See Section 6.3.1.
The correct answer is: an event listener

Question 3

Incorrect

Mark 0.00 out of 1.00

Which one of the following is NOT part of the signature of a Java method?

Select one:
a. method name

b. names of formal parameters

c. number of formal parameters 

d. types of formal parameters

Your answer is incorrect.


The names of formal parameters are only important for the implementation of the method. See Section 4.3.3 of Eck (2014).
The correct answer is: names of formal parameters

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 3/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 4

Correct

Mark 1.00 out of 1.00

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!

Your answer is correct.


Notice the extra ";" at the end of the for loop. The loop iterates 9 times, but it does not output anything. Then the separate code block
runs once and outputs "Hello". See Sections 3.1.1 and 3.4.1 of Eck (2014).
The correct answer is: 1

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 4/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 5

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

class Sum {
static int sum = 0;
static void add(int i) { sum += i; }
public static void main(String[] args) {
for (int i = 0; i < 10; i++) add(i);
System.out.println(sum);
}
}

Select one:
a. 0

b. 9

c. 10

d. 45 

e. 100

Your answer is correct.


The "add" method adds the value of its parameter to the static member variable "sum". Thus "sum" gets the value
0+1+2+3+4+5+6+7+8+9, or 45. See Sections 4.2.4 and 4.3.2 of Eck (2014).
The correct answer is: 45

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 5/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 6

Correct

Mark 1.00 out of 1.00

Consider the following Java program, which one of the following best describes "count"?
public class Food {
static int count;
private String flavor = "sweet";
Food() { count++; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food();
System.out.println(pepper.getFlavor());
}
}

Select one:
a. a class variable 

b. a constructor

c. a local object variable

d. an instance variable

e. a method

Your answer is correct.

See Section 5.1.1 of Eck (2014).

The correct answer is: a class variable

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 6/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 7

Correct

Mark 1.00 out of 1.00

Consider the following Java method. Which term best describes what this method computes?
static int doSomething(int[] a) {
int b = 0;
for (int c : a) b += c;
return b;
}

Select one:
a. average

b. maximum

c. minimum

d. sum 

e. transpose

Your answer is correct.


See Section 7.5.1 and Chapter 7 Exercise 2.

The correct answer is: sum

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 7/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 8

Incorrect

Mark 0.00 out of 1.00

What is the output of the following Java program?

import java.util.*;
class ArrayGames {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 1; i <= 5; i++) a.add(i);
Integer n = 3;
a.remove(n);
System.out.println(a.toString());
}
}

Select one:
a. [0, 1, 2, 4, 5]

b. [1, 2, 3, 4, 5]

c. [1, 2, 3, 5] 

d. [1, 2, 4, 5]

e. [4, 5]

Your answer is incorrect.

This one is tricky. The "remove" method is overloaded for both "int" and the type of the ArrayList, which is "Integer". The "Integer"
version requires no conversions or unboxing, so the compiler picks that one. It removes the element with value "3", not the element
with index 3. See Section 7.3.1.
The correct answer is: [1, 2, 4, 5]

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 8/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 9

Incorrect

Mark 0.00 out of 1.00

Consider the following Java program. Which line gives the "TestFX" class access to the "Button" class definition?
import javafx.application.Application;

import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.application.Platform;

import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;

import javafx.scene.control.Button;
public class TestFX extends Application {

public void start(Stage stage) {


Button quitButton = new Button("Quit");

quitButton.setOnAction(e -> Platform.exit());


HBox buttonBar = new HBox(quitButton);

BorderPane root = new BorderPane();


root.setBottom(buttonBar);

Scene scene = new Scene(root, 100, 50);

stage.setScene(scene);
stage.show();

}
public static void main(String[] args) {

launch(args);
}

Select one:
a. Button quitButton = new Button("Quit");

b. import javafx.application.Application;

c. import javafx.scene.control.Button;

d. root.setBottom(buttonBar);

e. public class TestFX extends Application 

Your answer is incorrect.


See Section 6.3.1

The correct answer is: import javafx.scene.control.Button;

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 9/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 10

Correct

Mark 1.00 out of 1.00

Consider the following class definition. Which variables can be used in the missing "println" expression on line 20?

1 public class PrintStuff


2 {
3 public static void main()
4 {
6 {
7 int i = -1;
8 System.out.println(_____);
9 }
10 int j = 1;
11 for (j = 0; j < 10; j++) {
12 System.out.println(_____);
13 }
14 {
15 int k;
16 for (k = 0; k < 10; k++) {
17 System.out.println(_____);
18 }
19 }
20 System.out.println(_____);
21 }
22 }

Select one:
a. Only "i"

b. Only "j" 

c. Only "k"

d. "i" and "j"

e. "j" and "k"

Your answer is correct.


"i" and "k" are no longer in scope. Only "j" is still in scope. See Section 3.1.1 of Eck (2014).

The correct answer is: Only "j"

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 10/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 11

Incorrect

Mark 0.00 out of 1.00

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

Your answer is incorrect.


See Section 3.6.1 of Eck (2014).

The correct answer is: float

Question 12

Correct

Mark 1.00 out of 1.00

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

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 11/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 13

Incorrect

Mark 0.00 out of 1.00

What is the output of the following Java program?

abstract class Food {


abstract void printFlavor();
}
class Pepper extends Food {
void printFlavor() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food pepper = new Food();
pepper.printFlavor();
}
}

Select one:
a. bland

b. bland

spicy

c. no output 

d. spicy

e. the program does not compile

Your answer is incorrect.


The program tries to initialize "pepper" to an object of type "Food", but "Food" is an abstract class. Variables can have abstract classes
as their type, but objects cannot. See Section 5.5.5.
The correct answer is: the program does not compile

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 12/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 14

Correct

Mark 1.00 out of 1.00

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 

Your answer is correct.


See Section 2.1 of Eck (2014).

The correct answers are: a variable declaration, a class definition

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 13/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 15

Correct

Mark 1.00 out of 1.00

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

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 14/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 16

Correct

Mark 1.00 out of 1.00

Consider the following class definition. Which variables can be used in the missing "println" expression on line 8?

1 public class PrintStuff


2 {
3 public static void main()
4 {
6 {
7 int i = -1;
8 System.out.println(_____);
9 }
10 int j = 1;
11 for (j = 0; j < 10; j++) {
12 System.out.println(_____);
13 }
14 {
15 int k;
16 for (k = 0; k < 10; k++) {
17 System.out.println(_____);
18 }
19 }
20 System.out.println(_____);
21 }
22 }

Select one:
a. Only "i" 

b. Only "j"

c. Only "k"

d. "i" and "j"

e. "j" and "k"

Your answer is correct.


Only "i" is within scope. "j" and "k" have not been declared yet. See Section 3.1.1 of Eck (2014).
The correct answer is: Only "i"

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 15/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 17

Correct

Mark 1.00 out of 1.00

Consider the following Java program, which one of the following best describes "setFlavor"?
public class Food {
static int count;
private String flavor = "sweet";
Food() { count++; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food();
System.out.println(pepper.getFlavor());
}
}

Select one:
a. a class variable

b. a constructor

c. a local object variable

d. an instance variable

e. a method 

Your answer is correct.


See Section 5.1.1 of Eck (2014).

The correct answer is: a method

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 16/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 18

Correct

Mark 1.00 out of 1.00

Consider the following Java program. What is the superclass of "TestFX"?


import javafx.application.Application;
import javafx.scene.Scene;

import javafx.stage.Stage;
import javafx.application.Platform;
import javafx.scene.layout.BorderPane;

import javafx.scene.layout.HBox;
import javafx.scene.control.Button;
public class TestFX extends Application {
public void start(Stage stage) {

Button quitButton = new Button("Quit");


quitButton.setOnAction(e -> Platform.exit());
HBox buttonBar = new HBox(quitButton);
BorderPane root = new BorderPane();

root.setBottom(buttonBar);
Scene scene = new Scene(root, 100, 50);
stage.setScene(scene);

stage.show();
}
public static void main(String[] args) {
launch(args);

}
}

Select one:
a. ActionEvent

b. ActionListener

c. launch

d. start

e. Application 

Your answer is correct.

See Section 5.5.2.


The correct answer is: Application

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 17/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 19

Correct

Mark 1.00 out of 1.00

Consider the following Java program. Which statement registers an object to receive events?
import javafx.application.Application;
import javafx.scene.Scene;

import javafx.stage.Stage;
import javafx.application.Platform;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;

import javafx.scene.control.Button;
public class TestFX extends Application {
public void start(Stage stage) {
Button quitButton = new Button("Quit");

quitButton.setOnAction(e -> Platform.exit());


HBox buttonBar = new HBox(quitButton);
BorderPane root = new BorderPane();

root.setBottom(buttonBar);
Scene scene = new Scene(root, 100, 50);
stage.setScene(scene);
stage.show();

}
public static void main(String[] args) {
launch(args);
}

Select one:
a. import javafx.scene.control.Button;

b. Button quitButton = new Button("Quit");

c. quitButton.setOnAction(e -> Platform.exit()); 

d. root.setBottom(buttonBar);

e. stage.setScene(scene);

Your answer is correct.


See Section 6.3.1.

The correct answer is: quitButton.setOnAction(e -> Platform.exit());

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 18/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 20

Correct

Mark 1.00 out of 1.00

Which of the following can a class NOT be used for?

Select one:
a. a container for static methods (subroutines)

b. a container for static variables

c. a primitive type 

d. a type for method parameters

e. a type for variables

Your answer is correct.


Primitive types are not classes. See Section 2.3 of Eck (2014).
The correct answer is: a primitive type

Question 21

Correct

Mark 1.00 out of 1.00

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

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 19/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 22

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

class Food {
Food() { System.out.println("bland"); }
}
class Pepper extends Food {
Pepper() { System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[] args) {
Food lunch = new Pepper();
}
}

Select one:
a. bland

b. bland 

spicy

c. no output

d. spicy

e. the program does not compile

Your answer is correct.


To construct an object, the compiler automatically calls the constructors for any superclasses of an object (unless there is an explicit
"super" call). Thus, "Food()" prints "bland", and then "Pepper()" prints "spicy". See Section 5.6.3.
The correct answer is: bland
spicy

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 20/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 23

Incorrect

Mark 0.00 out of 1.00

What is the output of the following Java program?


import java.util.*;
class ArrayGames {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 1; i <= 5; i++) a.add(i);
System.out.println(a.get(a.get(2)));
}
}

Select one:
a. 1

b. 2

c. 3 

d. 4

e. 5

Your answer is incorrect.


The ArrayList has elements {1,2,3,4,5}. Because indices start at 0, "a.get(2)" returns the 3rd element, 3. Then "a.get(3)" returns 4. See
Section 7.3.1.
The correct answer is: 4

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 21/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 24

Incorrect

Mark 0.00 out of 1.00

Assume "test" is a boolean variable. Which of the following expressions is equivalent to "test == true"?

Select one:
a. test

b. !test

c. test = true 

d. test.equals(true)

e. None of the above

Your answer is incorrect.

See Section 3.3.2 of Eck (2014).


The correct answer is: test

Question 25

Correct

Mark 1.00 out of 1.00

A class that implements a listener interface does which of the following?

Select one:
a. It generates events.

b. It handles events. 

c. It maintains an object directory.

d. It records audio.

e. It runs an event loop.

Your answer is correct.


See Section 6.3.1.
The correct answer is: It handles events.

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 22/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 26

Correct

Mark 1.00 out of 1.00

A Java method gets executed when it is...

Select one:
a. called 

b. compiled

c. declared

d. defined.
defined

e. imported

Your answer is correct.


See Section 4.2.2 of Eck (2014).

The correct answer is: called

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 23/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 27

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

import java.util.*;
class ArrayGames {
public static void main(String[] args) {
int[][] a = {{5,4,3,2,1},{-1,-2,-3,-4,-5}};
for (int[] b : a) Arrays.sort(b);
for (int[] b : a) System.out.print(Arrays.toString(b));
}
}

Select one:
a. [-5, -4, -3, -2, -1]

b. [-5, -4, -3, -2, -1][1, 2, 3, 4, 5]

c. [1, 2, 3, 4, 5]

d. [1, 2, 3, 4, 5][-5, -4, -3, -2, -1] 

e. [5, 4, 3, 2, 1][-1, -2, -3, -4, -5]

Your answer is correct.


The program sorts each row of the two-dimensional array, but it does not change the order of the rows. See Sections 7.2.2 and 7.5.1.
The correct answer is: [1, 2, 3, 4, 5][-5, -4, -3, -2, -1]

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 24/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 28

Correct

Mark 1.00 out of 1.00

Consider the following Java method, which term best describes "'("Hello, World!")"?

public static void main(String[] args) {


System.out.println("Hello, World!");
}

Select one:
a. actual parameter or argument 

b. formal parameter

c. method call

d. modifier

e. return type

Your answer is correct.


See Section 4.3.2 of Eck (2014).
The correct answer is: actual parameter or argument

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 25/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 29

Correct

Mark 1.00 out of 1.00

Consider the following Java method. Which term best describes what this method computes?
static void doSomething(int[][] a) {
int n = a.length;
for (int j = 0; j < n; j++) {
for (int i = j+1; i < n; i++) {
int aij = a[i][j];
a[i][j] = a[j][i];
a[j][i] = aij;
}
}
}

Select one:
a. average

b. maximum

c. minimum

d. sum

e. transpose 

Your answer is correct.


See Section 7.5.1 and Chapter 7 Exercise 2.
The correct answer is: transpose

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 26/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 30

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

class Food {
Food() { System.out.println("bland"); }
}
class Pepper extends Food {
Pepper() { this("spicy"); }
Pepper(String flavor) { System.out.println(flavor); }
}
public class Lunch {
public static void main(String[] args) {
Food lunch = new Pepper();
}
}

Select one:
a. bland

b. bland 

spicy

c. no output

d. spicy

e. the program does not compile

Your answer is correct.


First the "Food" constructor prints "bland". Then the "Pepper" constructor that takes no parameters calls 'this("spicy")', which represents
the "Pepper" constructor that takes a String parameter. It prints its parameter, "spicy". See Section 5.6.3.
The correct answer is: bland
spicy

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 27/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 31

Correct

Mark 1.00 out of 1.00

Which of the following keywords is useful for processing lists of menu options?

Select one:
a. break

b. continue

c. do

d. switch 

e. while

Your answer is correct.


See Section 3.6.2 of Eck (2014).
The correct answer is: switch

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 28/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 32

Correct

Mark 1.00 out of 1.00

Consider the following class definition. Which variables can be used in the missing "println" expression on line 12?

1 public class PrintStuff


2 {
3 public static void main()
4 {
6 {
7 int i = -1;
8 System.out.println(_____);
9 }
10 int j = 1;
11 for (j = 0; j < 10; j++) {
12 System.out.println(_____);
13 }
14 {
15 int k;
16 for (k = 0; k < 10; k++) {
17 System.out.println(_____);
18 }
19 }
20 System.out.println(_____);
21 }
22 }

Select one:
a. Only "i"

b. Only "j" 

c. Only "k"

d. "i" and "j"

e. "j" and "k"

Your answer is correct.


"i" is no longer in scope. "k" has not been declared yet. See Section 3.1.1 of Eck (2014).
The correct answer is: Only "j"

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 29/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 33

Incorrect

Mark 0.00 out of 1.00

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.

Your answer is incorrect.

See Section 3.3.2 of Eck (2014).


The correct answer is: At least once, at the end of each iteration.

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 30/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 34

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?

public class Food {


static int count;
private String flavor = "sweet";
Food() { count++; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food();
pepper.setFlavor("spicy");
System.out.println(pepper.getFlavor());
}
}

Select one:
a. 1

b. 2

c. spicy 

d. sweet

e. The program does not compile.

Your answer is correct.


See Section 5.1.3 of Eck (2014).
The correct answer is: spicy

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 31/32
8/10/22, 6:21 PM Review Quiz: Attempt review

Question 35

Correct

Mark 1.00 out of 1.00

What is the output of the following Java program?


public class Food {
static int count;
private String flavor = "sweet";
Food(String s) { flavor = s; }
void setFlavor(String s) { flavor = s; }
String getFlavor() { return flavor; }
static public void main(String[] args) {
Food pepper = new Food("spicy");
Food chile = pepper;
pepper.setFlavor("smoky");
System.out.println(pepper == chile);
}
}

Select one:
a. true 

b. false

c. smoky

d. spicy

e. sweet

Your answer is correct.


Setting "chile = pepper" causes the two object variables to refer to the same single object. Their values, which are the memory location
of the object, are thus equal. See Section 5.1.2 of Eck (2014).
The correct answer is: true

◄ Learning Guide Unit 9

Jump to...

https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 32/32

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy