6/28/2021 JFo Java Foundations Final Exam
Section 6
(Answer all questions in this section)
1. Given:
for(int i = 0; i > 10; i++){ }
What type of variable is i?
(1/1) Points
Member
Global
Local (*)
Static
Correct
2. The initialization expression initializes the loop and it is executed only once, as the loop begins.
(1/1) Points
True (*)
False
Correct
3. When is an update expression in a for loop executed?
(1/1) Points
Before the first iteration through the loop.
Before each iteration through the loop.
After each iteration through the loop. (*)
After two iterations 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?
(1/1) Points
Condition Expression , Update Expression
Initialization Expression , Update Expression
Initialization Expression , Condition Expression , Update Expression (*)
Initialization Expression , Condition Expression
Correct
5. Which statement is NOT true about do-while loops?
(1/1) Points
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
Statements in the loop are executed once until the condition becomes false.
Statements in the loop are executed once initially, and then the condition is evaluated.
Statements in the loop are executed repeatedly until the condition becomes false.
The number of times a do-while loop is executed is dependent upon the value of the counter variable. (*)
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 6
(Answer all questions in this section)
6. The while loop continually executes a block of statements while a particular condition is false.
(1/1) Points
True
False (*)
Correct
7. Which statement is false about infinite loop?
(1/1) Points
An infinite loop is a code which will execute until the user interrupts the program
The body of a while loop eventually must make the condition false to avoid infinite loop.
An infinite loop is generally caused by a programming mistake.
An infinite loop is a commonly the result of a syntax error. (*)
Correct
8. Which is used to terminate a loop?
(1/1) Points
break (*)
continue
switch
catch
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/1) Points
True (*)
False
Correct
Section 7
(Answer all questions in this section)
10. You can write more than one constructor in a class.
(1/1) Points
True (*)
False
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 7
(Answer all questions in this section)
11. All overloaded methods share the same name.
(1/1) Points
True (*)
False
Correct
12. Which three can vary in overloaded methods?
(1/1) Points
Order of parameters. (*)
The names of parameters
Number of parameters. (*)
Types of parameters. (*)
Method return type.
Correct
13. Which type of memory is allocated for the code below?
int x = 1;
int y = 2;
x=y;
(1/1) Points
Stack memory (*)
PileDriver memory
No memory is allocated
Heap memory
Correct
14. What is the output of the following code?
String s1 = "Hello";
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);
(1/1) Points
s1: Hello
s2: Welcome!
s1: Welcome!
s2: Hello
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
s1: Welcome!
s2: Welcome! (*)
s1: Hello
s2: Hello
Correct
15. Which is stored within the stack memory?
(1/1) Points
Local variables (*)
Strings
Instance variables
Objects
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 7
(Answer all questions in this section)
16. Class name should follow Camel casing rules.
(1/1) Points
True (*)
False
Correct
17. Which two statements are true about the main method?
(1/1) Points
The main method should store the properties and behaviors of objects.
The main method should be as simple as possible. (*)
The main method is commonly used to instantiate objects. (*)
The main method should be able to freely manipulate an object’s fields.
Correct
18. 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/1) Points
True
False (*)
Correct
19. To make fields directly accessible to other classes, the class fields must be marked public.
(1/1) Points
True (*)
False
Correct
20. An object reference directs you from one object to another.
(1/1) Points
True (*)
False
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/1
6/28/2021 JFo Java Foundations Final Exam
Section 7
(Answer all questions in this section)
21. Which two statements are true?
(1/1) Points
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 methods. (*)
An object can access another object’s public constructor.
Correct
22. 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/1) Points
A static variable. (*)
A private variable.
A local variable.
A public variable.
Correct
23. 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);
}
}
(1/1) Points
The variable name has a null value.
It would be possible to call the display() method and attempt to reference an object’s name before any object exists. (*)
Static variables are only accessible from instance methods.
Static variables cannot be referenced from methods.
Correct
24. How would you instantiate the Employee class from a main method located in another class?
public class Employee{
private String name;
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
private double salary;
public Employee(String n, double s){
name = n;
salary = s;
}
}
(1/1) Points
Employee emp1 = new Employee();
Employee emp1 = new Employee(50000);
Employee emp1 = new Employee(50000, "Syam");
Employee emp1 = new Employee("Syam", 50000); (*)
Correct
25. An object reference with a null value points to an empty location in memory.
(1/1) Points
True (*)
False
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 7
(Answer all questions in this section)
26. Which statement is true about the default constructor of a class?
(1/1) Points
Java automatically provides a constructor for every class. (*)
You must write a default constructor.
The default constructor always returns void.
Default constructor should have at least one argument.
Correct
27. 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
}
}
(1/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
28. You create an Employee object with a String employeeName field. What is the default value for employeeName?
(1/1) Points
null (*)
A space
“Name”
“default”
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
Correct
Section 8
(Answer all questions in this section)
29. Using the NetBeans debugger, you can set breakpoints and trace through a program one line at a time.
(1/1) Points
True (*)
False
Correct
30. Runtime errors can be caught by Java’s exception handling mechanism.
(1/1) Points
True (*)
False
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 8
(Answer all questions in this section)
31. Which is not a compilation error?
(1/1) Points
int x=2
x = ( 3 + 5;
int y;
y++; (*)
y = 3 + * 5;
Correct
32. Identify where there is a potential bug in this code:
int radiusOfCircle = 10;
int areaOfCircle = Math.PI * radiusOfCircle * radiusOfCircle;
(1/1) Points
A variable name is misspelled.
A semi-colon is missing.
A datatype is incorrect. (*)
A variable hasn’t been assigned a value.
Correct
33. Which code goes in the try block?
(1/1) Points
Any code that is likely to cause an exception. (*)
Any code that is safe from an exception.
Any code that can handle an exception.
Any code that is likely to print the exception details.
Correct
34. Each catch block is an exception handler that handles the type of exception indicated by its argument.
(1/1) Points
True (*)
False
Correct
35. Which two cannot be stored in an ArrayList?
(1/1) Points
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
int (*)
float (*)
Integer
String
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 8
(Answer all questions in this section)
36. A wrapper class encapsulates, or wraps, the primitive types within an object.
(1/1) Points
True (*)
False
Correct
37. Which two are limitations of an array of primitives (ie: int[] x)?
(1/1) Points
You can create only one array in a class.
The size of the array is fixed during array creation and cannot grow once initialized. (*)
You cannot overwrite the contents of an array once initialized.
You need to create your own methods to manipulate array contents. (*)
Correct
38. Which is not used to traverse an ArrayList?
(0/1) Points
ListIterator
for-each loop
iterator
do- while loop (*)
Incorrect. Refer to Section 8 Lesson 2.
39. What is the starting index of an array?
(1/1) Points
It depends on the type of the array.
1
0 (*)
You can start with anything
Correct
40. Arrays are like variables which must be declared prior to use.
(1/1) Points
True (*)
False
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 8
(Answer all questions in this section)
41. Which loop type is specially designed to traverse an array?
(1/1) Points
do while loop
for loop (*)
repeat loop
while loop
Correct
42. An array allows you to create a single identifier that can be used to organize many items of the same data type.
(1/1) Points
True (*)
False
Correct
Section 9
(Answer all questions in this section)
43. Which method helps to set the width of a rectangle’s outline?
(1/1) Points
setStrokeWidth(double d) (*)
setStroke(Paint paint)
setLayoutX(double d)
setX(double d)
Correct
44. Which color is not directly used when creating custom Color.rgb()?
(1/1) Points
Blue
Green
Red
Yellow (*)
Correct
45. JavaFX doesn’t provide you with UI elements, shapes and text. So you must always create your own graphics.
(1/1) Points
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/2
6/28/2021 JFo Java Foundations Final Exam
True
False (*)
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 2/2
6/28/2021 JFo Java Foundations Final Exam
Section 9
(Answer all questions in this section)
46. Audio can be played by referencing the Audio object directly.
(1/1) Points
True (*)
False
Correct
47. Lambda Expressions provide much more effective and cleaner syntax for working with GUI applications and sorting lists.
(1/1) Points
True (*)
False
Correct
48. The start() method is the entry point for all JavaFX applications.
(1/1) Points
True (*)
False
Correct
49. Which type of Root Node allows Nodes to be placed anywhere?
(1/1) Points
Group (*)
TilePane
StackPane
HBox
Correct
50. A layout Pane dictates how Nodes must be positioned
(1/1) Points
True (*)
False
Correct
https://myacademy.oracle.com/player/play?in_sessionid=5103025A91A3A042&classroom_id=75055645 1/1