You are on page 1of 33

Section 6 Quiz

(Answer all questions in this section)


1. Which statement is true?

Mark for Review

(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

parentheses of a while loop.

A while loop boolean expression is made up of a counter, increment, and test.

A counter (i) is declared and initialized inside the while loop.


Incorrect. Refer to Section 6 Lesson 2.

2. Which loop type is considered to be a post-test loop?

Mark for Review

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

Mark for Review

(1) Points

True (*)

False
Correct

4. The while loop continually executes a block of statements while a particular condition is false.

Mark for Review

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

Mark for Review

(1) Points

True (*)
False
Correct
6. Which two statements are true about the while loop.

Mark for Review

(1) Points

If the condition of the loop is true initially, the statements are never executed.

The statements of a while loop will execute one or more times.

If the condition of a pre-test loop is false, the statements in the loop are never executed.(*)

The statement in a while loop will execute zero or more times.(*)


Incorrect. Refer to Section 6 Lesson 2.

7. The only way to exit a loop is for the loop condition to evaluate to false.

Mark for Review

(1) Points

True

False (*)
Incorrect. Refer to Section 6 Lesson 3.

8. Which two statements are true about the break statement?

Mark for Review

(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

comes out of the program.


When a break statement is executed inside a loop, the loop-statement is terminated immediately.(*)

The execution of the program will stop at the statement following the loop-statement.
Incorrect. Refer to Section 6 Lesson 3.

9. Which is used to terminate a loop?

Mark for Review

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

Mark for Review


(1) Points

True (*)

False
Correct
11. The initialization expression initializes the loop and it is executed only once, as the loop begins.

Mark for Review

(1) Points

True (*)

False
Correct

12. When is an update expression in a for loop executed?

Mark for Review

(1) Points

Before the first iteration through the loop.

After each iteration through the loop. (*)

Before each iteration through the loop.

After two iterations through the loop.


Incorrect. Refer to Section 6 Lesson 1.

13. In the given syntax of for loop, which part represents the header section?

for (initialization; condition; update) {


// Code statement(s) }

Mark for Review

(1) Points

for (initialization; condition; update) { Code statement(s) }

Code statement(s)

for (initialization; condition; update) (*)

for (initialization; condition; update) { }


Incorrect. Refer to Section 6 Lesson 1.

14. Looping continues as long as the boolean expression in the for loop is false.

Mark for Review

(1) Points

True

False (*)
Incorrect. Refer to Section 6 Lesson 1.

15. What is the result?


public static void main(String[] args) {
    for (;;) {
     System.out.println("Welcome to Java");
   }
}

Mark for Review

(1) Points

Compilation error as expressions are missing in the for loop.

Program prints “Welcome to Java” once.

No error and no output.

Program prints “Welcome to Java” an infinite number of times. (*)


Incorrect. Refer to Section 6 Lesson 1.
Section 6 Quiz
(Answer all questions in this section)
1. Which statement will produce the output: 2, 4, 6, 8, 10?

Mark for Review

(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

2. A for loop is also called a definite loop

Mark for Review

(1) Points

True (*)

False
Correct

3. When is an update expression in a for loop executed?

Mark for Review

(1) Points

After each iteration through the loop. (*)

After two iterations through the loop.


Before each iteration through the loop.

Before the first iteration through the loop.


Correct

4. You need to calculate the squares of numbers from 1 to 5. Which of the items should be present in
your looping statement?

Mark for Review

(1) Points

Initialization Expression , Condition Expression , Update Expression (*)

Initialization Expression , Condition Expression

Initialization Expression , Update Expression

Condition Expression , Update Expression


Correct

5. Which is not a looping statement in Java?

Mark for Review

(1) Points

while

for

switch (*)

do-while
Correct
6. Which two operators cannot be used as the conditional expression in a for loop?

Mark for Review

(1) Points

<

==

!<(*)

!=

!>(*)
Correct

7. The purpose of adding comments is to increase the ability to understand the logic easily.

Mark for Review

(1) Points

True (*)

False
Correct
8. 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;
    }
   System.out.println("var1:" + var1 + ", var2:" + var2);
   }
 }
}

Mark for Review

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

Mark for Review

(1) Points

True (*)
False
Correct

10. A post-test loop evaluates its condition at the end of the loop instead of the beginning.

Mark for Review

(1) Points

True (*)

False
Correct
11. Which statement is true?

Mark for Review

(1) Points
The counter which gets incremented determines the number of loop iterations is within the

parentheses of a while loop.


The boolean expression that determines the number of loop iterations is within the parentheses of a

while loop. (*)

A while loop boolean expression is made up of a counter, increment, and test.

A counter (i) is declared and initialized inside the while loop.


Correct

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.

Mark for Review

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

Mark for Review

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

Mark for Review

(1) Points

True (*)

False
Correct
15. Which two statements are true about the while loop.

Mark for Review

(1) Points

The statements of a while loop will execute one or more times.

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.

The statement in a while loop will execute zero or more times.(*)


Correct
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)
Section 7 Quiz 1 - L1-L3
(Answer all questions in this section)
1. Objects are accessed using reference variables.

Mark for Review

(1) Points

True (*)

False
Correct
2. Which type of memory is allocated for the code below?

int x = 1;
int y = 2;
x=y;

Mark for Review

(1) Points

No memory is allocated

Stack memory (*)

PileDriver memory

Heap memory
Correct

3. Which is stored within the stack memory?

Mark for Review

(1) Points

Instance variables

Objects

Strings

Local variables (*)
Correct

4. In this statement, identify the type of the variable s.

Student s = new Student();

Mark for Review

(1) Points

Student (*)

null

String

Class
Correct

5. In the following statements, how many employee objects are created?

Employee e1 = new Employee();


Employee e2 = new Employee();
Employee e3 = new Employee();

Mark for Review

(1) Points

3 (*)
0

1
Correct
6. Which two statements are true about objects of the same class?

Mark for Review

(1) Points

All objects are equal.

Each object will have the same reference variable to the location in memory.

Each new instance of an object will have a different location in memory.(*)

All objects of the same class have the same methods.(*)


Incorrect. Refer to Section 7 Lesson 2.

7. An object reference with a null value points to an empty location in memory.

Mark for Review

(1) Points

True (*)

False
Correct

8. Which has a default value of null?

Mark for Review

(1) Points

boolean

int

String (*)

double
Correct

9. When you write your own constructor, the default constructor is no longer available.

Mark for Review

(1) Points

True (*)

False
Correct

10. Which two statements are NOT true about constructors?

Mark for Review

(1) Points
A constructor method may return a value.(*)

A constructor method is called once for each instance of an object.

The constructor method is called during instantiation.

A constructor method has a void return type.(*)


Correct
11. If fields aren't initialized, they take on a default value.

Mark for Review

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

public class Employee{


   private String name;
   private double salary;
   public Employee(String name, double salary){
     //initialize name
     //initialize salary
   }
}

Mark for Review

(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

13. Which two statements are true about the main method?

Mark for Review

(1) Points
The main method should store the properties and behaviors of objects.

The main method should be able to freely manipulate an object’s fields.

The main method should be as simple as possible.(*)

The main method is commonly used to instantiate objects.(*)


Incorrect. Refer to Section 7 Lesson 1.

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?

Mark for Review

(1) Points

True

False (*)
Correct

15. The structure of a class consists of properties and behaviors.

Mark for Review

(1) Points

True (*)

False
Correct
Section 7 Quiz 2 - L4-L6
(Answer all questions in this section)
1. Which two statements are true?

Mark for Review

(1) Points

An object can access another object’s public methods.(*)

An object can access another object’s public fields.(*)

An object can access another object’s main method.

An object can access another object’s public constructor.


Correct

2. Which two are access modifiers?

Mark for Review

(1) Points

static

private(*)

public(*)

final
Correct
3. Access and visibility of a class should be limited as much as possible.

Mark for Review

(1) Points

True (*)

False
Correct

4. Which two statements are true?

Mark for Review

(1) Points

The purpose of a setter method is to modify a public field

The purpose of a getter method is to grant other classes access to public data.

The purpose of a setter method is to allow private data to be modified safely(*)

The purpose of a getter method is to return the value of a private field(*)


Incorrect. Refer to Section 7 Lesson 5.

5. To make fields directly accessible to other classes, the class fields must be marked public.

Mark for Review

(1) Points

True (*)

False
Correct
6. What is encapsulation?

Mark for Review

(1) Points

A technique for debugging.

A technique for limiting one class’s visibility to another. (*)

A technique for writing more than one main method.

A technique for including primitives within an ArrayList.


Correct

7. Which two statements are true about private access modifier?

Mark for Review

(1) Points

Class fields marked private are visible to any class.

Class fields marked private are most secure.(*)

Class fields are typically marked public.

Class fields are typically marked private.(*)


Correct
8. Method overloading can be a useful technique for defining methods with similar functionality or
calculations.

Mark for Review

(1) Points

True (*)

False
Correct

9. You can write more than one constructor in a class.

Mark for Review

(1) Points

True (*)

False
Correct

10. Which statement is true?

Mark for Review

(1) Points

The default constructor can accept arguments.

The default constructor is still available when you add your own constructor.

You must write at least one constructor in your class.

A constructor can be written to accept arguments. (*)


Correct
11. Methods can call other methods in the same class.

Mark for Review

(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”?

public class Employee{


   public static int employeeID;
   public String name;

   public static void display(){


     System.out.println(employeeID);
     System.out.println(name);
   }
}

Mark for Review


(1) Points
It would be possible to call the display() method and attempt to reference an object’s name before any

object exists. (*)

The variable name has a null value.

Static variables are only accessible from instance methods.

Static variables cannot be referenced from methods.


Correct

13. Static variables of a class can be accessed, even if the class has not been instantiated.

Mark for Review

(1) Points

True (*)

False
Correct

14. The fields and methods of the Math class cannot be directly accessed as they are static.

Mark for Review

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

Mark for Review

(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. What is the starting index of an array?

Mark for Review

(1) Points

You can start with anything

0 (*)

It depends on the type of the array.


Correct

2. Which two are valid array declarations?

Mark for Review

(1) Points

int array size;

int[] size;(*)

[]int size;

int size[];(*)
Correct

3. You can access the size of any array by using the array’s “length” property.

Mark for Review

(1) Points

True (*)

False
Correct
4. What is the output?
int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);

Mark for Review

(1) Points

ArrayIndexOutOfBoundsException

10 (*)
Correct

5. Which loop type is specially designed to traverse an array?

Mark for Review

(1) Points

do while loop

for loop (*)

repeat loop

while loop
Correct
6. Arrays are like variables which must be declared prior to use.

Mark for Review

(1) Points

True (*)

False
Correct

7. Runtime errors can be caught by Java’s exception handling mechanism.

Mark for Review

(1) Points

True (*)

False
Correct

8. Using the NetBeans debugger, you can set breakpoints and trace through a program one line at a
time.

Mark for Review

(1) Points

True (*)
False
Correct

9. Which is not a compilation error?

Mark for Review

(1) Points

x = ( 3 + 5;

int x=2
int y;

y++; (*)

y = 3 + * 5;
Incorrect. Refer to Section 8 Lesson 4.

10. What is the danger of catching a generic Exception type as shown below?

int[] array = {10, 20, 30};


int b = 0;
try{
   System.out.println("1");
   int c = (array[3] / b);
   System.out.println("2");
}
catch(Exception ex){
   System.out.println(ex.toString());
}

Mark for Review

(1) Points

The details of the Exception object ex are too general to be useful. (*)

An Exception will never occur.

An ArithmeticException cannot be caught.

An ArrayIndexOutOfBoundsException cannot be caught.


Correct

11. If the try block succeeds then no exception has occurred.

Mark for Review

(1) Points

True (*)

False
Correct

12. Which exception is thrown when an application attempts to use null when an object is required?

Mark for Review

(1) Points
NullPointerException (*)

FileNotFoundException

ArithmeticException

ArrayIndexOutOfBoundsException
Incorrect. Refer to Section 8 Lesson 3.

13. Which two cannot be stored in an ArrayList?

Mark for Review

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

Mark for Review

(1) Points

True (*)

False
Correct

15. You can access elements in an ArrayList by their index.

Mark for Review

(1) Points

True (*)

False
Correct

 Final Exam Java Foundation Oracle Academy Answer Key


Langsung saja check this out soal dan jawaban quiz 9 – Java Foundation-nya!
 
1. When you write code for MouseEvents, you are telling a Node to listen for a particular event
o True (*)
o False
2. Lambda Expressions provide much more effective and cleaner syntax for working with GUI
applications and sorting lists
o True (*)
o False
2. Which method is used to for mouse click events
o setOnMouseMoved()
o setOnMouseClicked() (*)
o setOnMouseDragged()
o setOnMouseReleased()
o JavaFX doesn’t provide you with UI elements, shapes and text. So you must always
create your own graphics
o True
o False (*)
o Audio can be played by referencing the Audio object directly
o True (*)
o False
o 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, 0, 255);
o Color customColor = Color.rgb(0, 255, 0);
o Color customColor = Color.rgb(0, 255, 255); (*)
o Which method helps to set the width of a rectangle’s outline
o setStrokeWidth(double d) (*)
o setX(double d)
o setLayoutX(double d)
o setStroke(Paint paint)
o JavaFX Ensemble contains code examples of JavaFX features
o True (*)
o False
o Which color is not directly used when creating custom Color.rgb()?
o Yellow (*)
o Green
o Blue
o Red
o Which is the correct syntax to instantiate a JavaFX Rectangle
o Rectangle rect = new Rectangle(20, 20, 100, 200); (*)
o Rectangle rect = new Rectangle(20, 20);
o Rectangle rect = Rectangle(20, 20, 100, 200);
o Rectangle rect = new Rectangle(20, 20, 100);
o A layout Pane dictates how Nodes must be positioned
o True (*)
o False
12. The start() method is the entry point for all JavaFX applications
o True (*)
o False
13. Which type of Root Node allows Nodes to be placed anywhere
o StackPane
o HBox
o Group (*)
o TilePane
14. JavaFX is used to create GUI applications
o True (*)
o False
15. Which is not a JavaFX Node?
o Button
o Object (*)
o ImageView
o ScrollBar
Section 9 Quiz
(Answer all questions in this section)
1. An Image is an object that describes the location of a graphics file.

Mark for Review

(1) Points
True (*)

False
Correct

2. Audio can be played by referencing the Audio object directly.

Mark for Review

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

Mark for Review

(1) Points

True

False (*)
Correct

4. Which method is used to for mouse click events?

Mark for Review

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

Mark for Review

(1) Points

True (*)

False
Correct
6. The start() method is the entry point for all JavaFX applications.

Mark for Review

(1) Points

True (*)

False
Correct
7. JavaFX is used to create GUI applications.

Mark for Review

(1) Points

True (*)

False
Correct

8. Which is not a JavaFX Node?

Mark for Review

(1) Points

ImageView

Object (*)

Button

ScrollBar
Correct

9. A layout Pane dictates how Nodes must be positioned

Mark for Review

(1) Points

True (*)

False
Correct

10. How would you set the title of the Stage primaryStage?

Mark for Review

(1) Points

primaryStage.setTitle("New Title!"); (*)

primaryStage.title = "New Title!";

primaryStage = "New Title!;

primaryStage("New Title!");
Correct
11. JavaFX Ensemble contains code examples of JavaFX features.

Mark for Review

(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

Color customColor = Color.rgb(0, 255, 0);

Color customColor = Color.rgb(0, 0, 255);

Color customColor = Color.rgb(255, 255, 0);

Color customColor = Color.rgb(0, 255, 255); (*)


Incorrect. Refer to Section 9 Lesson 2.

13. Which color is not directly used when creating custom Color.rgb()?

Mark for Review

(1) Points

Green

Red

Yellow (*)

Blue
Correct

14. Which is the correct syntax to instantiate a JavaFX Rectangle?

Mark for Review

(1) Points

Rectangle rect = Rectangle(20, 20, 100, 200);

Rectangle rect = new Rectangle(20, 20, 100, 200); (*)

Rectangle rect = new Rectangle(20, 20);

Rectangle rect = new Rectangle(20, 20, 100);


Correct

15. Which method helps to set the width of a rectangle’s outline?

Mark for Review

(1) Points

setX(double d)

setLayoutX(double d)

setStrokeWidth(double d) (*)

setStroke(Paint paint)
Correct

You might also like