Professional Documents
Culture Documents
Section 6 Quiz 10 PDF Free
Section 6 Quiz 10 PDF Free
(1) Points
The boolean expression that determines the number of loop iterations is within the parentheses of a
while loop. (*)
The counter which gets incremented determines the number of loop iterations is within the
(1) Points
do-while (*)
for
forEach
while
Incorrect. Refer to Section 6 Lesson 2.
3. A while loop is often used with Scanner input as you don't know many times you'll need to re-
prompt the user if they type bad data.
(1) Points
True (*)
False
Correct
4. The while loop continually executes a block of statements while a particular condition is false.
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
5. A do-while will always execute statements contained in the loop at least once.
(1) Points
True (*)
False
Correct
6. Which two statements are true about the while loop.
(1) Points
If the condition of the loop is true initially, the statements are never executed.
If the condition of a pre-test loop is false, the statements in the loop are never executed.(*)
7. The only way to exit a loop is for the loop condition to evaluate to false.
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 3.
(1) Points
The execution of the program will continue with the statement following the loop-statement.(*)
When a break statement is executed inside a loop, the loop-statement is terminated immediately and
The execution of the program will stop at the statement following the loop-statement.
Incorrect. Refer to Section 6 Lesson 3.
(1) Points
catch
break (*)
continue
switch
Incorrect. Refer to Section 6 Lesson 3.
10. Loops are used in programs for repeated execution of one or more statements until a terminating
condition is reached.
True (*)
False
Correct
11. The initialization expression initializes the loop and it is executed only once, as the loop begins.
(1) Points
True (*)
False
Correct
(1) Points
13. In the given syntax of for loop, which part represents the header section?
(1) Points
Code statement(s)
14. Looping continues as long as the boolean expression in the for loop is false.
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 1.
(1) Points
(1) Points
for (int i = 2; i <= 10; i += 2) {
System.out.print(i + " ");
} (*)
for (int i = 0; i < 8; i += 2) {
System.out.print(i + " ");
}
for (int i = 1; i < 10; i += 2) {
System.out.print(i + " ");
}
for (int i = 0; i < 10; i += 2) {
System.out.print(i + " ");
}
Correct
(1) Points
True (*)
False
Correct
(1) Points
4. You need to calculate the squares of numbers from 1 to 5. Which of the items should be present in
your looping statement?
(1) Points
(1) Points
while
for
switch (*)
do-while
Correct
6. Which two operators cannot be used as the conditional expression in a for loop?
(1) Points
<
==
!<(*)
!=
!>(*)
Correct
7. The purpose of adding comments is to increase the ability to understand the logic easily.
(1) Points
True (*)
False
Correct
8. What is the result?
(1) Points
var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
var1: 2, var2: 1
var1: 0, var2: 0
var1: 0, var2: 1
var1: 0, var2: 2
var1: 1, var2: 0
var1: 1, var2: 1
var1: 1, var2: 2
var1: 2, var2: 0
var1: 2, var2: 1
var1: 2, var2: 2
var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
(*)
var1: 0, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
Correct
9. A continue statement is used to skip the remaining statements in the body of a loop and continue
with the next iteration of the loop.
(1) Points
True (*)
False
Correct
10. A post-test loop evaluates its condition at the end of the loop instead of the beginning.
(1) Points
True (*)
False
Correct
11. Which statement is true?
(1) Points
The counter which gets incremented determines the number of loop iterations is within the
while loop. (*)
12. A while loop is often used with Scanner input as you don't know many times you'll need to re-
prompt the user if they type bad data.
(1) Points
True (*)
False
Incorrect. Refer to Section 6 Lesson 2.
13. The while loop continually executes a block of statements while a particular condition is false.
(1) Points
True
False (*)
Incorrect. Refer to Section 6 Lesson 2.
14. After the loop is terminated, the statement immediately following the loop body is executed.
(1) Points
True (*)
False
Correct
15. Which two statements are true about the while loop.
(1) Points
If the condition of a pre-test loop is false, the statements in the loop are never executed.(*)
If the condition of the loop is true initially, the statements are never executed.
(1) Points
True (*)
False
Correct
2. Which type of memory is allocated for the code below?
int x = 1;
int y = 2;
x=y;
(1) Points
No memory is allocated
Stack memory (*)
PileDriver memory
Heap memory
Correct
(1) Points
Instance variables
Objects
Strings
Local variables (*)
Correct
(1) Points
Student (*)
null
String
Class
Correct
5. In the following statements, how many employee objects are created?
(1) Points
3 (*)
0
1
Correct
6. Which two statements are true about objects of the same class?
(1) Points
Each object will have the same reference variable to the location in memory.
7. An object reference with a null value points to an empty location in memory.
(1) Points
True (*)
False
Correct
(1) Points
boolean
int
String (*)
double
Correct
9. When you write your own constructor, the default constructor is no longer available.
(1) Points
True (*)
False
Correct
(1) Points
A constructor method may return a value.(*)
(1) Points
True (*)
False
Correct
12. How could you write the Employee constructor so that its parameters are named the same as the
fields they’re initializing?
(1) Points
public Employee(String name, double salary){
name = name;
salary = salary;
}
public Employee(String name, double salary){
name = this.name;
salary = this.salary;
}
public Employee(String name, double salary){
this.name = name;
this.salary = salary;
} (*)
public Employee(String name, double salary){
this.name = this.name;
this.salary = this.salary;
}
Correct
(1) Points
The main method should store the properties and behaviors of objects.
14. You have created an Employee class with all required fields and methods. 10 employees join the
company. Should you copy and paste the Employee class for all 10 employees?
(1) Points
True
False (*)
Correct
(1) Points
True (*)
False
Correct
Section 7 Quiz 2 - L4-L6
(Answer all questions in this section)
1. Which two statements are true?
(1) Points
(1) Points
static
private(*)
public(*)
final
Correct
3. Access and visibility of a class should be limited as much as possible.
(1) Points
True (*)
False
Correct
(1) Points
The purpose of a getter method is to grant other classes access to public data.
5. To make fields directly accessible to other classes, the class fields must be marked public.
(1) Points
True (*)
False
Correct
6. What is encapsulation?
(1) Points
(1) Points
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
Correct
(1) Points
The default constructor is still available when you add your own constructor.
(1) Points
True (*)
False
Correct
12. Given the following code, why does your IDE complain that “non-static variable name cannot be
referenced from a static context”?
object exists. (*)
13. Static variables of a class can be accessed, even if the class has not been instantiated.
(1) Points
True (*)
False
Correct
14. The fields and methods of the Math class cannot be directly accessed as they are static.
(1) Points
True
False (*)
Correct
15. If you need to make a particular variable belong to a class rather than any individual instance,
what type of variable should you use?
(1) Points
A private variable.
A public variable.
A local variable.
A static variable. (*)
Correct
Langsung saja check this out soal dan jawaban Final Exam – Java Foundation-nya!
oh iya catatan : jawabannya yang ada tanda (*) dan ada efek bold pada font-nya.
sudah mimin atur supaya mudah membedakannya ya! check guys!
1. The only way to exit a loop is for the loop condition to evaluate to false.
o True
o False (*)
2. What is the result?public static void main(String[] args) {
for (int var1 = 0; var1 < 2; var1++) {
for (int var2 = 0; var2 < 2; var2++) {
if (var2 == 2) {
continue;
}
out.println(“var1:” + var1 + “, var2:” + var2);
}
}
}
o var1: 0, var2: 0
var1: 0, var2: 1
var1: 0, var2: 2
var1: 1, var2: 0
var1: 1, var2: 1
var1: 1, var2: 2
var1: 2, var2: 0
var1: 2, var2: 1
var1: 2, var2: 2
o var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1 (*)
o var1: 0, var2: 0
var1: 0, var2: 1
var1: 1, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
var1: 2, var2: 1
o var1: 0, var2: 0
var1: 1, var2: 1
var1: 2, var2: 0
3. Which two statements are true about the while loop. (Choose all correct answers)
o The statements of a while loop will execute one or more times.
o The statement in a while loop will execute zero or more times. (*)
o If the condition of a pre-test loop is false, the statements in the loop are never
executed. (*)
o If the condition of the loop is true initially, the statements are never executed.
4. Which loop type is considered to be a post-test loop?
o while
o do-while (*)
o for
o forEach
5. The while loop continually executes a block of statements while a particular condition is false.
o True
o False (*)
6. Which two are valid syntax to create a for loop? (Choose all correct answers)
o for(int i = 10, i >= 0, i++ ) {
System.out.println(“i=”+i);
}
o for(int i = 10; i >= 0; i++ ) {
System.out.println(“i=”+i);
} (*)
o for(int i = 10 i >= 0; i++ ) {
System.out.println(“i=”+i);
}
o for(int i = 10; i >= 0; ) {
System.out.println(“i=”+i);
} (*)
7. The initialization expression initializes the loop and it is executed only once, as the loop
begins.
o True
o False (*)
8. Which two operators cannot be used as the conditional expression in a for loop? (Choose all
correct answers)
o !> (*)
o ==
o <
o !=
o !< (*)
9. What is the result?
public static void main(String[] args) {
for (;;) {
System.out.println(“Welcome to Java”);
}
}
o Compilation error as expressions are missing in the for loop.
o Program prints “Welcome to Java” once.
o No error and no output.
o Program prints “Welcome to Java” an infinite number of times. (*)
10. How would you complete this code so that one add method calls the other add method?
public int add(int a, int b, int c) {
return(a+b+c);
}
public int add(int a, int b){
//Complete this line.
}
o return add(a, b, 0); (*)
o return (a, b);
o return add(a, b, c);
o return (a, b, c);
11. You can write more than one constructor in a class.
o True (*)
o False
12. Setters are void return type methods.
o True (*)
o False
13. Which two are access modifiers? (Choose all correct answers)
o static
o private (*)
o public (*)
o final
14. Which two statements are true? (Choose all correct answers)
o An object can access another object’s main method.
o An object can access another object’s public methods. (*)
o An object can access another object’s public constructor.
o An object can access another object’s public fields. (*)
15. In the following statements, how many employee objects are created?
Employee e1 = new Employee();
Employee e2 = new Employee();
Employee e3 = new Employee();
o 3 (*)
o 0
o 2
o 1
16. Objects are stored within the heap memory.
o True (*)
o False
17. Java developers don’t need to know an object’s location in memory.
o True (*)
o False
18. The fields and methods of the Math class cannot be directly accessed as they are static.
o True
o False (*)
19. If you need to make a particular variable belong to a class rather than any individual instance,
what type of variable should you use?
o A local variable.
o A private variable.
o A static variable. (*)
o A public variable.
20. How would you instantiate the Employee class from a main method located in another class?
public class Employee{
private String name;
private double salary;
public Employee(String n, double s){
name = n;
salary = s;
}
}
o Employee emp1 = new Employee();
o Employee emp1 = new Employee(50000);
o Employee emp1 = new Employee(50000, “Syam”);
o Employee emp1 = new Employee(“Syam”, 50000); (*)
21. If fields aren’t initialized, they take on a default value.
o True (*)
o False
22. Which two statements are NOT true about constructors? (Choose all correct answers)
o A constructor method may return a value. (*)
o A constructor method is called once for each instance of an object.
o The constructor method is called during instantiation.
o A constructor method has a void return type. (*)
23. In Java, the this keyword can be used to reference the current object’s fields and methods.
o True (*)
o False
24. What will happen when you try to access an object reference with a null value?
o NullPointerException. (*)
o The value null is retrieved from the memory location.
o An empty object is returned.
o You will get a compilation error.
25. Class name should follow Camel casing rules.
o True (*)
o False
26. The structure of a class consists of properties and behaviors.
o True (*)
o False
27. You have created an Employee class with all required fields and methods. 10 employees join
the company. Should you copy and paste the Employee class for all 10 employees?
o True
o False (*)
28. What is the output?
int[] array = {10, 20, 30};
int b = 0;
try{
System.out.println(“1”);
int c = (array[3] / b);
System.out.println(“2”);
}
catch(ArithmeticException ex){
System.out.println(“Arithmetic Exception”);
}
catch(ArrayIndexOutOfBoundsException ex){
System.out.println(“Array index out of bounds”);
}
o 1
Arithmetic Exception
o 1
Array index out of bounds (*)
o 1
2
Array index out of bounds
o 1
2
Array index out of bounds
29. Which code goes in the try block?
o Any code that is likely to cause an exception. (*)
o Any code that is safe from an exception.
o Any code that can handle an exception.
o Any code that is likely to print the exception details.
30. What is the output?
int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);
o 10 (*)
o ArrayIndexOutOfBoundsException
o 1
o 0
31. Given:
int x[];
What is the value of x?
o 0
o 1
o null (*)
o Some random number.
32. What is the output?
int[] arr = new int[2];
for(int i=0; i < arr.length; i++){
System.out.print(“hai “);
}
o hai
o hai hai hai
o hai hai (*)
o 12
33. What is an array?
o An array is a way to create multiple copies of a single value.
o An array is a Java primitive type.
o An array is an indexed container that holds a set of values of a single type. (*)
o An array is an indexed container that holds a set of values of a multiple types.
34. Using the NetBeans debugger, you can set breakpoints and trace through a program one line
at a time.
o True (*)
o False
35. What are two disadvantages of adding print statements for debugging? (Choose all correct
answers)
o Print statements cannot print the values of an object’s fields.
o It’s tedious to remove print statements. (*)
o Print statements cannot print the values of variables.
o Too many print statements lead to information overload. (*)
36. Runtime errors can be caught by Java’s exception handling mechanism.
o True (*)
o False
37. Which is not a compilation error?
o int y;
o y++; (*)
o y = 3 + * 5;
o x = ( 3 + 5;
o int x=2
38. You can access elements in an ArrayList by their index.
o True (*)
o False
39. Which is NOT a benefit of ArrayList class?
o You can remove all of the elements of an ArrayList with a method.
o An ArrayList grows as you add elements.
o An ArrayList shrinks as you remove elements.
o You can use an ArrayList list to store Java primitive values (like int). (*)
40. How could you declare an ArrayList so that it can store true or false values?
o ArrayList<boolean> arrList = new ArrayList<>();
o ArrayList<true, false> arrList = new ArrayList<>();
o ArrayList<Boolean> arrList = new ArrayList<>(); (*)
o ArrayList<True, False> arrList = new ArrayList<>();
41. Which of the following is not a wrapper class?
o String (*)
o Boolean
o Integer
o Byte
42. JavaFX doesn’t provide you with UI elements, shapes and text. So you must always create
your own graphics.
o True
o False (*)
43. Audio can be played by referencing the Audio object directly.
o True (*)
o False
44. Which method is used to for mouse click events?
o setOnMouseReleased()
o setOnMouseDragged()
o setOnMouseMoved()
o setOnMouseClicked() (*)
45. Which is the correct syntax to instantiate a JavaFX Rectangle?
o Rectangle rect = Rectangle(20, 20, 100, 200);
o Rectangle rect = new Rectangle(20, 20, 100);
o Rectangle rect = new Rectangle(20, 20, 100, 200); (*)
o Rectangle rect = new Rectangle(20, 20);
46. How would you create a custom color that is pure cyan (equal parts green and blue)?
o Color customColor = Color.rgb(255, 255, 0);
o Color customColor = Color.rgb(0, 255, 255); (*)
o Color customColor = Color.rgb(0, 0, 255);
o Color customColor = Color.rgb(0, 255, 0);
45. A layout Pane dictates how Nodes must be positioned
o True (*)
o False
45. Which is not a JavaFX Node?
o Object (*)
o ImageView
o Button
o ScrollBar
46. JavaFX is used to create GUI applications.
o True (*)
o False
47. Given the method:
void add(double a, double b)
Which method signature would not overload this method?
o void add(String a, String b)
o int add (double a, double b) (*)
o void add (double a, int b)
o void add(int a, int b)
o void add(int a, int b, int c)
(1) Points
0 (*)
(1) Points
int[] size;(*)
[]int size;
int size[];(*)
Correct
3. You can access the size of any array by using the array’s “length” property.
(1) Points
True (*)
False
Correct
4. What is the output?
int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);
(1) Points
ArrayIndexOutOfBoundsException
10 (*)
Correct
(1) Points
do while loop
for loop (*)
repeat loop
while loop
Correct
6. Arrays are like variables which must be declared prior to use.
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
Correct
8. Using the NetBeans debugger, you can set breakpoints and trace through a program one line at a
time.
(1) Points
True (*)
False
Correct
(1) Points
x = ( 3 + 5;
int x=2
int y;
y++; (*)
y = 3 + * 5;
Incorrect. Refer to Section 8 Lesson 4.
(1) Points
(1) Points
True (*)
False
Correct
12. Which exception is thrown when an application attempts to use null when an object is required?
(1) Points
NullPointerException (*)
FileNotFoundException
ArithmeticException
ArrayIndexOutOfBoundsException
Incorrect. Refer to Section 8 Lesson 3.
(1) Points
Integer
int(*)
String
float(*)
Incorrect. Refer to Section 8 Lesson 2.
14. A wrapper class encapsulates, or wraps, the primitive types within an object.
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
Correct
(1) Points
True (*)
False
Correct
3. JavaFX doesn’t provide you with UI elements, shapes and text. So you must always create your
own graphics.
(1) Points
True
False (*)
Correct
(1) Points
setOnMouseClicked() (*)
setOnMouseReleased()
setOnMouseDragged()
setOnMouseMoved()
Correct
5. When you write code for MouseEvents, you are telling a Node to listen for a particular event.
(1) Points
True (*)
False
Correct
6. The start() method is the entry point for all JavaFX applications.
(1) Points
True (*)
False
Correct
7. JavaFX is used to create GUI applications.
(1) Points
True (*)
False
Correct
(1) Points
ImageView
Object (*)
Button
ScrollBar
Correct
(1) Points
True (*)
False
Correct
(1) Points
primaryStage.setTitle("New Title!"); (*)
primaryStage("New Title!");
Correct
11. JavaFX Ensemble contains code examples of JavaFX features.
(1) Points
True (*)
False
Correct
12. How would you create a custom color that is pure cyan (equal parts green and blue)?
Mark for Review
(1) Points
(1) Points
Green
Red
Yellow (*)
Blue
Correct
(1) Points
(1) Points
setX(double d)
setLayoutX(double d)
setStrokeWidth(double d) (*)
setStroke(Paint paint)
Correct