Review Quiz - Attempt Review Cs1102
Review Quiz - Attempt Review Cs1102
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
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
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
Select one:
a. an event generator
b. an event listener
c. an event loop
d. an event method
e. javafx.scene.input.MouseEvent;
Question 3
Incorrect
Which one of the following is NOT part of the signature of a Java method?
Select one:
a. method name
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
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
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
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
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
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
d. an instance variable
e. a method
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
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
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
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]
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
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 {
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);
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
Consider the following class definition. Which variables can be used in the missing "println" expression on line 20?
Select one:
a. Only "i"
b. Only "j"
c. Only "k"
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
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
Question 12
Correct
Select one:
a. Runs Java programs
d. Translates source code in ".java" files into Java byte code in ".class" files
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
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
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
What is on line 1?
Select one:
a. a variable declaration
b. a statement
d. a comment
e. 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
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. ?
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
Consider the following class definition. Which variables can be used in the missing "println" expression on line 8?
Select one:
a. Only "i"
b. Only "j"
c. Only "k"
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
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
d. an instance variable
e. 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
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) {
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
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
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");
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;
d. root.setBottom(buttonBar);
e. stage.setScene(scene);
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
Select one:
a. a container for static methods (subroutines)
c. a primitive type
Question 21
Correct
Select one:
a. 0
b. 3
c. 4
d. 5
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
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
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
Select one:
a. 1
b. 2
c. 3
d. 4
e. 5
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
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)
Question 25
Correct
Select one:
a. It generates events.
b. It handles events.
d. It records audio.
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
Select one:
a. called
b. compiled
c. declared
d. defined.
defined
e. imported
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
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]
c. [1, 2, 3, 4, 5]
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
Consider the following Java method, which term best describes "'("Hello, World!")"?
Select one:
a. actual parameter or argument
b. formal parameter
c. method call
d. modifier
e. return type
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
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
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
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
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
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
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
Consider the following class definition. Which variables can be used in the missing "println" expression on line 12?
Select one:
a. Only "i"
b. Only "j"
c. Only "k"
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
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.
c. Exactly once.
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
Select one:
a. 1
b. 2
c. spicy
d. sweet
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
Select one:
a. true
b. false
c. smoky
d. spicy
e. sweet
Jump to...
https://my.uopeople.edu/mod/quiz/review.php?attempt=8309997&cmid=298483 32/32