Wednesday, January 3, 2018

Kunci Jawaban All Quiz Oracle Academy Java Fundamental 2017 Part 18

1.  What is printed by the following code segment?    Mark for Review (1) Points
  
  
\\\\ 
  
\\\\\\\ (*) 
  
\\\\\\\\\\\\\\ 
  
\\ 
  
  

 Correct 
  
 
2.  Consider the following code snippet.
   What is printed?
 Mark for Review (1) Points
  
  
Cayrbniz 
  
CayrbnizCayrbniz 
  
yr (*) 
  
ay 
  
ArrayIndexOutofBoundsException is thrown 
  
  
 Incorrect. Refer to Section 4 Lesson 4. 
  
 
3.  What will the following code segment output?  String s="\\\n\"\n\\\n\""; System.out.println(s);
 Mark for Review (1) Points
  
  
\" \" 
  
""\ "" \
""      \ " \ " (*)       " \ " \ " " 
  
  
 Incorrect. Refer to Section 4 Lesson 4. 
  
 
4.  The following program prints "Not Equal". True or false?    Mark for Review (1) Points
  
  
True 
  
False (*) 
  
  
 Incorrect. Refer to Section 4 Lesson 4. 
  
 
5.  Which of the following creates a String named Char?
 Mark for Review (1) Points
  
  
char string; 
  
String Char; (*) 
  
char Char; 
  
char char; 
  
String char; 
  
  
 Correct   Section 4  (Answer all questions in this section)
    
 
6.  What is the purpose of the Eclipse Editor Area and Views?
 Mark for Review (1) Points
         (Choose all correct answers)
          To modify elements. (*) 
  
To navigate a hierarchy of information. (*) 
  
To choose the file system location to delete a file. 
    
   
 Incorrect. Refer to Section 4 Lesson 1. 
    
 
7.  The ______________ is the location into which you will store and save your files.
 Mark for Review (1) Points
          Perspective 
  
Workspace (*) 
  
Editor 
  
None of the above 
    
   
 Incorrect. Refer to Section 4 Lesson 1. 
    
 
8.  You need to _______________ Java code to generate a .class file
 Mark for Review (1) Points
          Collect 
  
Compile (*) 
  
Package 
  
Assemble 
    
   
 Incorrect. Refer to Section 4 Lesson 1. 
    
 
9.  Eclipse does not provide views to help you navigate a hierarchy of information. True or False?  Mark for Review (1) Points
          True 
  
False (*) 
    
   
 Correct 
    
 
10.  For every opening curly brace { there does not need to be a closing curly brace} for the program to compile without error. True or False?  Mark for Review (1) Points
          True 
  
False (*) 
    
      Incorrect. Refer to Section 4 Lesson 1.   11.  When importin g another package into a class you must import only the package classes that will be called and not  Mark for Review  (1) Points
the entire package . True or false?
          True 
  
False (*) 
          Incorrect. Refer to Section 4 Lesson 2. 
    
 
12.  Which of the two diagrams below illustrate the general form of a Java program?   Mark for Review (1) Points
          Example A 
  
Example B (*) 
          Correct 
    
 
13.  Select the statement that declares a number of type double and initializes it to 6 times 10 to the 5th power.  Mark for Review (1) Points
          double number=6*10^5; 
  
double number=6e5; (*) 
  
double number=6(e5); 
  
double number=6*10e5; 
          Incorrect. Refer to Section 4 Lesson 3. 
    
 
14.  What two values can a boolean variable have?
 Mark for Review (1) Points
          Numbers and characters 
  
True and false (*) 
  
Relational and logic operators 
  
Arithmetic and logic operators 
  
Integers and floating point types 
          Correct 
     
       Section 5  (Answer all questions in this section)
    
 
15.  Which of the following is true about a do-while loop?
 Mark for Review (1) Points
          It is a post-test loop. 
  
It is a modified while loop that allows the program to run through the loop once before testing the boolean condition. 
  
It continues looping until the condition becomes false. 
  
All of the above. (*) 
          Incorrect. Refer to Section 5 Lesson 2.   (Answer all questions in this secti on)
    
 
16. How many times will the following loop be executed?  What is the value of x after the loop has finished?  What is the value of count after the loop has finished?
int count = 17; int x = 1; while(count > x){ x*=3;
 Mark for Review (1) Points
count-=3; }
          4; 8; 27 
  
3; 27; 8 (*) 
  
5; 27; 8 
  
5; 30; 5 
  
3; 9; 11 
    
   
 Incorrect. Refer to Section 5 Lesson 2. 
    
 
17. Why are loops useful?
 Mark for Review (1) Points
          They save programmers from having to rewrite code. 
  
They allow for repeating code a variable number of times. 
  
They allow for repeating code until a certain argument is met. 
  
All of the above. (*) 
    
   
 Incorrect. Refer to Section 5 Lesson 2. 
    
 
18. In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?  Mark for Review (1) Points
          True 
  
False (*) 
    
   
 Incorrect. Refer to Section 5 Lesson 1. 
    
 
19. This keyword is used to instruct specific code when the input for a switch statement that does not match any of the cases.  Mark for Review (1) Points
          Switch 
  
Case 
  
Break 
  
Default (*) 
  
None of the above 
    
   
 Incorrect. Refer to Section 5 Lesson 1. 
    
 
20. Which of the following could be a reason to use a switch statement in a Java program?  Mark for Review (1) Points
          Because it allows the code to be run through until a certain conditional statement is true.       Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)       Because it terminates the current loop. 
  
Because it allows the user to enter an input in the console screen and prints out
a message that the user input was successfully read in.
    
      Incorrect. Refer to Section 5 Lesson 1.   2 1.  What is the output of the following segment of code?    Mark for Review  (1) Points
         321111      11 (*)      111      1111      This code doesn't compile. 
    
   
Incorrect. Refer to Section 6 Lesson 1. 
    
 
22. What is the output of the following segment of code? 
 Mar k for Review (1) Points
         321123      642      642246 (*)      312213      This code doesn't compile. 
    
   
Correct 
    
 
23. Which of the following statements is not a valid array declaration?  Mar k for Review (1) Points
         int number[];      float []averages;      double marks[5];      counter int[]; (*) 
    
   
Incorrect. Refer to Section 6 Lesson 1. 
    
 
24. What is the output of the following segment of code if the command line arguments are "a b c d e f g"? 
 Mar k for Review (1) Points
         f      e (*)      c      d      This code doesn't compile. 
    
   
Incorrect. Refer to Section 6 Lesson 1. 
    
 
25. Suppose you misspell a method name when you call it in your program. Which of the following explains why this gives you an exception?
 Mar k for Review (1) Points
         Because the parameters of the method were not met.      Because the interpreter does not recognize this method since it was never initialized, the correct spelling of the method was initialized.      Because the interpreter tries to read the method but when it finds the method you intended to use it crashes.      This will not give you an exception, it will give you an error when the program is compiled. (*) 
    
   
Incorrect. Refer to Section 6 Lesson 3. 
26.  Of the options below, what is the fastest run- time?
 Mark for Review (1) Points
          n 
  
n^2 
  
lg(n) (*) 
  
n*lg(n) 
          Incorrect. Refer to Section 6 Lesson 2. 
    
 
27.  Selection sort is efficient for large arrays. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
28.  Binary searches can be performed on sorted and unsorted data. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
29.  A sequntial search is an iteration through the array that stops at the index where the desired element is found. True or false?  Mark for Review (1) Points
          True (*) 
  
False 
          Correct 
     
       Section 7  (Answer all questions in this section)
    
 
30.  What is the Java Applet?
 Mark for Review (1) Points
         (Choose all correct answers)
          It is the virtual machine that translates Java code into a representation that the computer can understand.       A web-based Java program that is embedded into a web browser. (*) 
  
A graphic visual included in Java. (*) 
  
There is no such thing as a Java Applet. 
          Incorrect. Refer to Section 7 Lesson 4.   31 .  Why is it not possible to extend more than one class at a time in an inherita nce hierarch Mark for Review  (1) Points
y chain?
          It is not necessary considering all public content is passed from super class to subclass and further to their subclass and that subclass' subclass and so on. (*)       Because the computer cannot handle code that complex. 
  
To prevent confusion for the programmer. 
  
It is possible to extend more than one class at a time. 
    
   
Incorrect. Refer to Section 7 Lesson 4. 
    
 
32. Which of the following correctly describes an "is-a" relationship?
 Mark for Review (1) Points
          A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)       A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.       It restricts access to a specified segment of code. 
  
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. 
    
   
Correct 
    
 
33. Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass SqueakyRobot?  Mark for Review (1) Points
          Robot.needOil(SqueakyRobot); 
  
SqueakyRobot.needOil(); 
  
super.needOil(); (*) 
  
needOil(Robot); 
    
   
Incorrect. Refer to Section 7 Lesson 4. 
    
 
34. It is possible to overload a method that is not a constructor. True or False?
 Mark for Review (1) Points
          True (*) 
  
False 
    
   
Correct 
    
 
35. Identify the error(s) in the class below. Choose all that apply.   Mark for Review (1) Points
         (Choose all correct answers)
          No method named min is defined. (*) 
  
Two methods cannot have the same name. 
  
The parameters must be the same for all methods with the same name. 
  
Private cannot be used as an access modifier. 
  
Final cannot be used as an access modifier. 
    
     Incorrect. Refer to Section 7 Lesson 2.   36.  Which of the following could be a reason to return an object?  Mark for Review (1) Points
          Because you wish to be able to use that object inside of the method. 
  
It has faster performance than returning a primitive type. 
  
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*) 
  
None of the above. It is not possible to return an object. 
          Incorrect. Refer to Section 7 Lesson 2. 
        37.  Which of the following is the definition for a variable argument method?
 Mark for Review
(1) Points
          A way to create a new class. 
  
Specifies accessibility to code. 
  
Having more than one constructor with the same name but different arguments. 
  
A type of argument that enables calling the same method with a different number of arguments. (*) 
          Incorrect. Refer to Section 7 Lesson 2. 
    
 
38.  Which segment of code correctly defines a method that contains two objects of class Tree as parameters?  Mark for Review (1) Points
          void bloom(Tree pine, Tree oak) {//code here }; (*) 
  
Tree bloom (pine, oak) {//code here }; 
  
void bloom, Tree pine, Tree oak {//code here }; 
  
None of the above, objects cannot be passed as parameters. 
          Correct 
    
 
39.  Abstract classes cannot implement interfaces. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 5. 
    
 
40.  What is Polymorphism?
 Mark for Review (1) Points
          A way of redefining methods with the same return type and parameters. 
  
A way to create multiple methods with the same name but different parameters. 
  
A class that cannot be initiated. 
  
The concept that a variable or reference can hold multiple types of objects. (*) 
          Incorrect. Refer to Section 7 Lesson 5.   41.  It is possible to inherit from an abstract class. True or false?  Mark for Review (1) Points
          True (*) 
  
False 
    
    Correct 
    
 
42.  Static methods can return any object type. True or false?
 Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 7 Lesson 3. 
    
 
43.  A non-linear recursive method is less expensive than a linear recursive method. True or false?  Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 3. 
    
 
44.  Forward thinking helps when creating linear recursive methods. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
45.  What is wrong with the following class declaration? 
class Account{ ;  private int number;  private String name;;  public Account;  }
 Mark for Review (1) Points
          Classes cannot include strings. 
  
Classes cannot include mixed data types. 
  
The constructor method has no definition. (*) 
  
There is nothing wrong. 
          Incorrect. Refer to Section 7 Lesson 1.   4 6 .  Which of the following creates an instance of the class below?    Mar k for Review  (1) Points
          ThisClass t=new ThisClass(); 
  
ThisClass t; 
  
ThisClass t=new ThisClass(3,4); 
  
ThisClass t=new ThisClass(5); (*) 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
47. A class can only have one constructor. True or false?
 Mar k for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
48. Which of the following creates a method that returns a boolean value?  Mar k for Review (1) Points
          
    
   
(*)      

  
None of the above. 
          Correct 
    
 
49. The constructor method must always have at least one parameter. True or false?  Mar k for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
50. Identify the driver class that correctly initializes employees Jane and Brandon. The Employee class is below.
public class Employee { private String name;  private int age;  private double salary; public Employee(String n, int a, double s) { name = n;  age = a;  salary = s;  } //methods for this class would go here }
 Mar k for Review (1) Points
          public class driver_class { public static void main(String[] args) { Employee Jane = new Employee("Jane", 48, 35.00); Employee Brandon = new Employee("Brandon", 36, 20.00);  } } (*)       public class driver_class { public static void main(String[] args) { Employee("Jane", 48, 35.00); Employee("Brandon", 36, 20.00);  } }       public class driver_class { public Employee{ Jane = new Employee("Jane", 48, 35.00); Brandon = new Employee("Brandon", 36, 20.00); 
} }      public class Employee { public class driver-class{ Employee Jane = new Employee(); Employee Brandon = new Employee();  } } 
          Incorrect. Refer to Section 7 Lesson 1.   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)
  
 
1 .  Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type.
Mark for Review (1) Points
  
  
char, int, double, long, String (*) 
  
boolean, byte, int, long, Short 
  
char, int, long, float, String 
  
char, boolean, float, long, String 
  
char, double, int, long, String 
  
   
 Incorrect. Refer to Section 4 Lesson 3.  
  
 
2 .  Which of the following is the name of a Java primitive data type?
Mark for Review (1) Points
  
  
Object 
  
Rectangle 
  
double (*) 
  
String 
  
   
 Incorrect. Refer to Section 4 Lesson 3.  
  
 
3 .  Which of the following defines an object class?
Mark for Review (1) Points
  
  
Contains a main method and other static methods. 
  
Contains classes that define objects. (*) 
  
Contains a main method, a package, static methods, and classes that define objects. 
  
None of the above. 
  
   
 Incorrect. Refer to Section 4 Lesson 2.  
  
 
4 .  Which of the two diagrams below illustrate the general form of a Java program?
Mark for Review (1) Points
  
  
Example A 
  
Example B (*) 
  
   
 Incorrect. Refer to Section 4 Lesson 2.  
  
 
5 .  The == operator tests if two String references are pointing to the same String object. True or false?
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
   
 Incorrect. Refer to Section 4 Lesson 4.        6 .  The followin g code is an example of creating a String reference : 
String s;
True or false?
Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 4 Lesson 4.  
    
 
7.  Given the code
String s1 = "abcdef"; String s2 = "abcdef"; String s3 = new String(s1);
Which of the following would equate to false?
Mark for Review (1) Points
          s1 == s2 
  
s1 = s2 
  
s3 == s1 (*) 
  
s1.equals(s2) 
  
s3.equals(s1) 
    
    Correct  
    
 
8.  Consider the following code snippet.   
What is printed?
Mark for Review (1) Points
          0 
  
1 (*) 
  

  
11 
  
12 
          Incorrect. Refer to Section 4 Lesson 4.  
    
 
9.  The String methods equals and compareTo perform similar functions and differ in their return type. True or false?
Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 4 Lesson 4.  
    
 
10.  A workspace is:
Mark for Review (1) Points
          The physical location onto which you will store and save your files. 
  
The location where all projects are developed and modified. 
  
The location where you can have one or more stored perspectives. 
  
All of the above. (*) 
          Incorrect. Refer to Section 4 Lesson 1.    11.  A perspective is described as:  Mark for Review  (1) Points
          A combination of views and editors (*) 
  
A combination of views and windows 
  
A combination of editor tabs 
  
None of the above 
    
  
 Correct  
    
 
12.  When you open more than one file in Eclipse the system will __________________.
Mark for Review  (1) Points
          Close the previously opened file. 
  
Use tabs to display all files open. (*) 
  
Put the new file opened in a View area only. 
  
None of the above. 
    
   
Incorrect. Refer to Section 4 Lesson 1.  
    
 
13.  What symbols are required for a compiler to ignore a comment?
Mark for Review  (1) Points
          // (*) 
  
/* 
  
*/ 
  
/*/ 
    
   
Incorrect. Refer to Section 4 Lesson 1.  
    
 
14.  A combination of views and editors are referred to as _______________.
Mark for Review  (1) Points
          A workspace 
  
A physical location 
  
A perspective (*) 
  
All of the above 
    
  
 Correct  
     
       Section 5  (Answer all questions in this section)
    
 
15.  Which of the following correctly matches the switch statement keyword to its function?
Mark for Review  (1) Points
         (Choose all correct answers)
          switch: tells the compiler the value to compare the input against 
  
default: signals what code to execute if the input
does not match any of the cases (*)
  
case: signals what code is executed if the user input matches the specified element (*) 
  
if: records the user's input and sends it to the case statements to find a possible match 
  
switch: identifies what element will be compared to the element of the case statements to find a possible match (*) 
    
   
Incorrect. Refer to Section 5 Lesson 1.  
16.  switch statements work on all input types including, but not limited to, int, char, and String. True or false?
Mark for Review  (1) Points
          True 
  
False (*) 
    
  
 Correct  
    
 
17. The three logic operators in Java are:
Mark for Review  (1) Points
          &&, ||, ! (*) 
  
!=,=,== 
  
&&,!=,= 
  
&,|,= 
    
  
 Correct  
    
 
18. Which of the following is true about a do-while loop?
Mark for Review  (1) Points
          It is a post-test loop. 
  
It is a modified while loop that allows the program to run through the loop once before testing the boolean condition. 
  
It continues looping until the condition becomes false. 
  
All of the above. (*) 
    
   
Incorrect. Refer to Section 5 Lesson 2.  
    
 
19. A counter used in a for loop cannot be initialized within the For loop header. True or false?
Mark for Review  (1) Points
          True 
  
False (*) 
    
  
 Correct  
    
 
20. In the code fragment below, the syntax for the for loop's initialization is correct. True or false?
public class ForLoop { public static void main (String args[]) { for ((int 1=10) (i<20) (i++))<br> {System.out.Println ("i: "+i); } } }
Mark for Review  (1) Points
          True 
  
False (*) 
    
   
Incorrect. Refer to Section 5 Lesson 2.  
21.  Which of the following is the correct lexicographical order for the conents of the int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}
Mark for Review (1) Points
          {71, 1, 3, 28,29, 50, 22, 83, 1, 17} 
  
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1} 
  
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83} 
  
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3} 
  
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83} (*) 
          Correct  
        22.  Selection sort is efficient for large arrays. True or
Mark for Review
false?  (1) Points
          True 
  
False (*) 
    
  
Incorrect. Refer to Section 6 Lesson 2.  
    
 
23.  Of the options below, what is the fastest run-time?
Mark for Review  (1) Points
          n 
  
n^2 
  
lg(n) (*) 
  
n*lg(n) 
    
  
Incorrect. Refer to Section 6 Lesson 2.  
    
 
24.  Why might a sequential search be inefficient?
Mark for Review  (1) Points
          It utilizes the "divide and conquer" method, which makes the algorithm more error prone. 
  
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*) 
  
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets. 
  
It is never inefficient. 
    
  
Incorrect. Refer to Section 6 Lesson 2.  
    
 
25.  Which of the following declares a one dimensional array named names of size 8 so that all entries can be Strings?
Mark for Review  (1) Points
          String names=new String[8]; 
  
String[] name=new Strings[8]; 
  
String[] names=new String[8]; (*) 
  
String[] name=String[8]; 
    
  
Incorrect. Refer to Section 6 Lesson 1.          26Which of Mark for
.  the following declares and initializes a one dimension al array named words of size 3 so that all entries can be Strings?
Review (1) Points
          String strings=new String[3]; 
  
String[] word={"Over","the","mountain"}; (*) 
  
String[] word=new String[3]; 
  
String[] words={"Oracle","Academy"}]; 
          Incorrect. Refer to Section 6 Lesson 1.  
    
 
27.  The following array declaration is valid. True or false?
int k[] = new int[10];
Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 6 Lesson 1.  
    
 
28.  What will be the content of the array variable table after executing the following code? 
Mark for Review (1) Points
          1 1 1 0 1 1 0 0 1 
  
1 0 0 0 1 0
0 0 1
  
1 0 0 1 1 0 1 1 1 (*) 
  
0 0 1 0 1 0 1 0 0 
          Correct  
    
 
29.  It is possible to throw and catch a second exception inside a catch block of code. True or false?
Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 6 Lesson 3.  
     
       Section 7  (Answer all questions in this section)
    
 
30.  The following statement compiles and executes. What do you know for certain? 
tree.grows(numFeet);
Mark for Review (1) Points
          numFeet must be an int. 
  
tree must be the name of the class. 
  
grows must be the name of an instance field. 
  
grows must be the name of a method. (*) 
  
tree must be a method. 
          Correct    3 1.  The basic unit of encapsulat ion in Java is the primitive data type. True or false?  Mark for Review (1) Points
          True 
  
False (*) 
          Correct  
    
 
32.  Instance variable names may only contain letters and digits. True or false?
Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 1.  
    
 
33.  A class can only have one constructor. True or false?
Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 7 Lesson 1.  
    
 
34.  What is the output of the following code segment: 
int n = 13; System.out.print(doNothing(n)); System.out.print(" ", n);
where the code from the method doNothing is:  public double doNothing(int n) { n = n + 8; return (double) 12/n; }
Mark for Review (1) Points
          1.75, 13 
  
0.571, 21 
  
1.75, 21 
  
0.571, 13 (*) 
          Incorrect. Refer to Section 7 Lesson 1.  
    
 
35.  What value will return for j when the setValue method is called?
Mark for Review (1) Points
          31 
  
32 
  
10 
  
11 (*) 
          Incorrect. Refer to Section 7 Lesson 1.   36.  Static methods can write to class variables. True or false?  Mark for Review  (1) Points
          True (*) 
  
False 
    
  
Incorrect. Refer to Section 7 Lesson 3.  
    
 
37.  Static methods can read instance variables. True or false?
Mark for Review  (1) Points
          True 
  
False (*) 
    
  
Incorrect. Refer to Section 7 Lesson 3.  
    
 
38.  Static methods can't act like "setter" methods. True or false?
Mark for Review  (1) Points
          True 
  
False (*) 
          Correct  
    
 
39.  If a class is immutable then it must be abstract. True or false?
Mark for Review  (1) Points
          True 
  
False (*) 
    
  
Incorrect. Refer to Section 7 Lesson 5.  
    
 
40.  Which of the following can be declared final?
Mark for Review  (1) Points
          Classes 
  
Methods 
  
Local variables 
  
Method parameters 
  
All of the above (*) 
    
  
Incorrect. Refer to Section 7 Lesson 5.  
41.  Consider the following method of the class Test:
public static List returnList(List list) { return list; } 
Which of the following program segments in Test's client class will compile with no errors? 
I. List nums = new ArrayList(); nums = Test.returnList(nums); II. ArrayList nums = new ArrayList();
Mark for Review  (1) Points
nums = Test.returnList(nums); III. ArrayList nums1 = new ArrayList(); List nums2 = Test.returnList(nums1);
         I only      I and III (*)      II only      II and III      I, II, and III 
    
   
Incorrect. Refer to Section 7 Lesson 5.  
    
 
42. Why are hierarchies useful for inheritance?
Mark for Review  (1) Points
         They keep track of where you are in your program.      They restrict a superclass to only have one subclass.      They organize constructors and methods in a simplified fashion.      They are used to organize the relationship between a superclass and its subclasses. (*) 
    
   
Incorrect. Refer to Section 7 Lesson 4.  
    
 
43. If a variable in a superclass is private, could it be directly accessed or modified by a subclass? Why or why not?
Mark for Review  (1) Points
         Yes. A subclass inherits full access to all contents of its super class.      Yes. Any variable passed through inheritance can be changed, but private methods cannot.      No. A private variable can only be modified by the same class with which it is declared regardless of its inheritance. (*)      No. Nothing inherited by the super class can be changed in the subclass. 
    
  
 Correct  
    
 
44. It is possible for a subclass to be a superclass. True or false?
Mark for Review  (1) Points
         True (*)      False 
    
   
Incorrect. Refer to Section 7 Lesson 4.  
    
 
45. If you inherit a class, you do not inherit the class' constructors. True or false?
Mark for Review  (1) Points
         True (*)      False 
    
  
 Correct  
4 6. Which of the follow ing is the definit ion for a variabl e argum ent metho d?
Mark for Review (1) Points
          A way to create a new class. 
  
Specifies accessibility to code. 
  
Having more than one constructor with the same name but different arguments. 
  
A type of argument that enables calling the same method with a different number of arguments. (*) 
          Incorrect. Refer to Section 7 Lesson 2.  
    
 
47.  Which of the following is the definition of a constructor?
Mark for Review (1) Points
          A keyword that specifies accessibility of code. 
  
A special method that is used to assign initial values to instance
variables in a class. (*)
  
A way to call a method with a variable number of arguments using an elipse. 
  
A variable in a method declaration that gets passed into the method. 
          Correct  
    
 
48.  Which of the following could be a reason to return an object?
Mark for Review (1) Points
          Because you wish to be able to use that object inside of the method. 
  
It has faster performance than returning a primitive type. 
  
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*) 
  
None of the above. It is not possible to return an object. 
          Incorrect. Refer to Section 7 Lesson 2.  
    
 
49.  Identify the error(s) in the class below. Choose all that apply.
Mark for Review (1) Points
         (Choose all correct answers)
          No method named min is defined. (*) 
  
Two methods cannot have the same name. 
  
The parameters must be the same for all methods with the same name. 
  
Private cannot be used as an access modifier. 
  
Final cannot be used as an access modifier. 
          Incorrect. Refer to Section 7 Lesson 2.  
    
 
50.  Which of the following is the correct way to code a method with a return type an object Automobile?
Mark for Review (1) Points
          Automobile upgrade(String carA){  carA="Turbo";  return carA;} 
  
Automobile upgrade(Automobile carA){  carA.setTurbo("yes");  return carA;} (*) 
  
String upgrade(String carA){  carA="Turbo";  return carA;} 
  
upgrade(Automobile carA) Automobile{  carA.setTurbo("yes");  return carA;} 
  
None of the above. It is not possible to return an object. 
          Correct   
1.  Suppose that str1 and str2 are two strings. Which of the statement s or expression s are valid?
 Mark for Review (1) Points
          String str3 = str1 - str2; 
  
str1 += str2; (*) 
  
str1 >= str2 
  
Str1 -= str2; 
    
  
 Incorrect. Refer to Section 4 Lesson 4. 
    
 
2.  The following program prints "Not Equal". True or false?    Mark for
Review (1) Points
          True 
  
False (*) 
    
  
 Incorrect. Refer to Section 4 Lesson 4. 
    
 
3.  When a String object is created it must be assigned a value. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
    
  
 Incorrect. Refer to Section 4 Lesson 4. 
    
 
4.  Which of the following creates a String reference named s and instantiates it?
 Mark for Review (1) Points
         (Choose all correct answers)
          String s=""; (*) 
  
s="s"; 
  
String s; 
  
String s=new String("s"); (*) 
    
  
 Incorrect. Refer to Section 4 Lesson 4. 
    
 
5.  What is printed by the following code segment?    Mark for Review (1) Points
          \\\\ 
  
\\\\\\\ (*) 
  
\\\\\\\\\\\\\\ 
  
\\ 
    
     Correct   6.  Which line of Java code  Mark for Review
properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers?
(1) Points
          double A=1/2*b*h; 
  
double A=1/2bh; 
  
double A=(double)1/(double)2*b*h; (*) 
  
double A=(double)(1/2)*b*h; 
          Incorrect. Refer to Section 4 Lesson 3. 
    
 
7. What are Java's primitive types?
 Mark for Review (1) Points
          boolean, byte, char, double, float, int, long, and short (*) 
  
boolean, byte, string, thread, int, double, long and short 
  
object, byte, string, char, float, int, long and short 
  
boolean, thread, stringbuffer, char, int, float, long and short 
  
boolean, thread, char, double, float, int, long and short 
          Incorrect. Refer to Section 4 Lesson 3. 
    
 
8. Which of the following defines a driver class?
 Mark for Review (1) Points
          Contains a main method and other static methods. (*) 
  
Contains classes that define objects. 
  
Contains a main method, a package, static methods, and classes that define objects. 
  
None of the above. 
          Incorrect. Refer to Section 4 Lesson 2. 
    
 
9. The following defines a package keyword:
 Mark for Review (1) Points
          Defines where this class lives relative to other classes, and provides a level of access control. (*)       Provides the compiler information that identifies outside classes used within the current class.       Precedes the name of the class. 
          Incorrect. Refer to Section 4 Lesson 2. 
    
 
10. A _______________ is used to organize Java related files.
 Mark for Review (1) Points
          Project 
  
Workspace 
  
Package (*) 
  
Collection 
          Incorrect. Refer to Section 4 Lesson 1.         11.  For every opening curly brace { there does not need to be a closing curly brace} for the program to compile without error. True or False?  Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
12.  You can return to the Eclipse Welcome Page by choosing Welcome from what menu?  Mark for Review (1) Points
          File 
  
Edit 
  
Help (*) 
  
Close 
          Incorrect. Refer to Section 4 Lesson 1. 
    
 
13.  Four variables are required to support a conversion of one unit of measure to another unit of measure. True or False?  Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 4 Lesson 1. 
    
 
14.  When converting gallons to liters its best to put the calculation result into a variable with a _______________ data type.  Mark for Review (1) Points
    
  
int 
  
double (*) 
  
boolean 
  
None of the above 
          Correct 
     
       Section 5  (Answer all questions in this section)
    
 
15.  How many times will the following loop be executed?  What is the value of x after the loop has finished?  What is the value of count after the loop has finished?
int count = 17; int x = 1; while(count > x){ x*=3; count-=3; }
 Mark for Review (1) Points
          4; 8; 27 
  
3; 27; 8 (*) 
  
5; 27; 8 
  
5; 30; 5 
  
3; 9; 11 
          Correct   16.  Why are loops useful ?  Mark for Review  (1) Points
          They save programmers from having to rewrite code. 
  
They allow for repeating code a variable number of times. 
  
They allow for repeating code until a certain argument is met. 
  
All of the above. (*) 
    
  
 Incorrect. Refer to Section 5 Lesson 2. 
    
 
17.  What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){<br> if(i%2 == 0) //your answer here else k+=3; }
 Mark for Review (1) Points
          continue; (*) 
  
break; 
  
return; 
  
k+=1; 
    
  
 Correct 
    
 
18.  Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user's input and sets it equal to a new String called input?
 Mark for Review (1) Points
          String input = in.next(); (*) 
  
String input = in.close(); 
  
String input = new String in.next(); 
  
String input = in.nextInt(); 
    
  
 Incorrect. Refer to Section 5 Lesson 1. 
    
 
19.  The following prints Yes on the screen. True or false?    Mark for Review (1) Points
          True 
  
False (*) 
    
  
 Correct 
    
 
20.  The six relational operators in Java are:
 Mark for Review (1) Points
          >,<,=,!,<=,>= 
  
>,<,==,!=,<=,>= (*) 
  
>,<,=,!=,<=,>= 
  
>,<,=,!=,=<,=> 
    
     Correct   21.  The followin g creates a referen ce in memory named q that  Mark for Review (1) Points
can refer to six differen t integers via an index. True or false?
int[] q = new int[8];
          True 
  
False (*) 
          Correct 
    
 
22.  double array[] = new double[8];   After execution of this statement, which of the following are true?
 Mark for Review (1) Points
          array[0] is undefined 
  
array[4] is null 
  
array[2] is 8 
  
array.length is 8 (*) 
          Incorrect. Refer to Section 6 Lesson 1. 
    
 
23.  The following creates a reference in memory named q that can refer to eight different doubles via an index. True or false?   double[] q = new double[8];
 Mark for Review (1) Points
          True (*) 
  
False 
          Correct 
    
 
24.  The following segment of code prints all five of the command line arguments entered into this program. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Incorrect. Refer to Section 6 Lesson 1. 
    
 
25.  Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?  Mark for Review (1) Points
          Sequential Search 
  
Merge Sort (*) 
  
Selection Sort 
  
Binary Search 
  
All of the above 
          Incorrect. Refer to Section 6 Lesson 2.   26.  Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)?  Mark for Review (1) Points
          Sequential Search 
  
Merge Sort 
  
Selection Sort 
  
Binary Search (*) 
  
All of the above 
    
  
 Correct 
    
 
27.  Binary searches can be performed on sorted and unsorted data. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
    
  
 Incorrect. Refer to Section 6 Lesson 2. 
    
 
28.  Selection sort is efficient for large arrays. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
    
  
 Correct 
    
 
29.  If an exception has already been thrown, what will the interpreter read next in the program?  Mark for Review (1) Points
          The next line of the program even if it is not the catch block of code. 
  
Where the program catches the exception. (*) 
  
The end of the program. 
  
The user input. 
    
  
 Incorrect. Refer to Section 6 Lesson 3. 
     
       Section 7  (Answer all questions in this section)
    
 
30.  Which of the following could be a reason to return an object?
 Mark for Review (1) Points
          Because you wish to be able to use that object inside of the method. 
  
It has faster performance than returning a primitive type. 
  
The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*) 
  
None of the above. It is not possible to return an object. 
    
     Incorrect. Refer to Section 7 Lesson 2.   31.  It is possible to return an object from a method. True or false?  Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 7 Lesson 2. 
    
 
32.  It is possible to overload a method that is not a constructor. True or False?
 Mark for Review (1) Points
          True (*) 
  
False 
          Correct 
    
 
33.  Which of the following is the correct way to code a method with a return type an object Automobile?  Mark for Review (1) Points
          Automobile upgrade(String carA){  carA="Turbo"; 
return carA;}      Automobile upgrade(Automobile carA){  carA.setTurbo("yes");  return carA;} (*)       String upgrade(String carA){  carA="Turbo";  return carA;}       upgrade(Automobile carA) Automobile{  carA.setTurbo("yes");  return carA;}       None of the above. It is not possible to return an object. 
          Correct 
    
 
34.  Which segment of code represents a correct way to define a variable argument method?  Mark for Review (1) Points
          String easyArray(String ... elems) {//code} (*) 
  
String easyArray(... String elems) {//code} 
  
String ... easyArray(String elems) {//code} 
  
Integer easyArray ... (int elems) {//code} 
          Incorrect. Refer to Section 7 Lesson 2. 
    
 
35.  What is true about the code below:
Car car1=new Car(); Car car2=new Car(); car2=car1;
 Mark for Review (1) Points
         (Choose all correct answers)
          The references car1 and car2 are pointing to two Car Objects in memory. 
  
The reference car2 points to an exact copy of the Car Object that car1 references. (*) 
  
There are no more Car objects in memory. 
  
There is a Car object that car1 referenced that is now slated for removal by the garbage collector. 
  
There is a Car object that car2 referenced that is now slated for removal by the garbage collector. (*) 
          Incorrect. Refer to Section 7 Lesson 1.   36 .  The following statement compiles and executes. What do you know for certain? 
tree.grows(num Feet);
 Mark for Review (1) Points
          numFeet must be an int. 
  
tree must be the name of the class. 
  
grows must be the name of an instance field. 
  
grows must be the name of a method. (*) 
  
tree must be a method. 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
37.  The basic unit of encapsulation in Java is the primitive data type. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
38.  The following code creates an object of type Animal. True or false?   Animal a=new Animal();
 Mark for Review (1) Points
          True (*) 
  
False 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
39.  What is the output of the following code segment: 
int n = 13; System.out.print(doNothing(n)); System.out.print(" ", n);
where the code from the method doNothing is:  public double doNothing(int n) { n = n + 8; return (double) 12/n; }
 Mark for Review (1) Points
          1.75, 13 
  
0.571, 21 
  
1.75, 21 
  
0.571, 13 (*) 
          Incorrect. Refer to Section 7 Lesson 1. 
    
 
40.  Which of the following creates an object from the Animal class listed below:    Mark for Review (1) Points
          Animal cat=new Animal(); 
  
Animal cat=Animal(50,30); 
  
Animal cat=new Animal(50,30); (*) 
  
Animal cat=new Animal(50); 
          Incorrect. Refer to Section 7 Lesson 1.   41.  A linear recursive method directly calls how many copies of itself in the recursive case?  Mark for Review (1) Points
          0 
  
1 (*) 
  
2 or more 
          Correct 
    
 
42.  Static methods can't act like "setter" methods. True or false?
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
43.  Any instance of the same class can assign a new value to a static variable. True or false?  Mark for Review (1) Points
          True (*) 
  
False 
          Correct 
    
 
44.  According to the following class declaration, runSpeed can be modified in class Cat. True or false?
public class Tiger extends Cat{ public int runSpeed; }
 Mark for Review (1) Points
          True 
  
False (*) 
          Correct 
    
 
45.  Which of the following correctly describes the use of the keyword super?
 Mark for Review (1) Points
          A keyword that restricts access to only inside the same class. 
  
A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*) 
  
A keyword that signals the end of a program. 
  
A keyword that allows access from anywhere. 
          Correct   4 6 . Consider creating a class Square that extends the Rectangle class provided below. Knowing that a square always has the same width and length, which of the following best represents a constructor for the Square class?   Mar k for Review (1) Points
          
    
   
    
(*)      None of the above. 
    
  
 Correct 
    
 
47. What is encapsulation?
 Mar k for Review (1) Points
         A keyword that allows or restricts access to data and methods.      A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.      A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom.      A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*) 
    
  
 Incorrect. Refer to Section 7 Lesson 4. 
    
 
48. If Oak extends Tree, it is possible to declare an object such that 
Tree grandfatherT = new Oak();  True or false?
 Mar k for Review (1) Points
         True (*)      False 
    
  
 Correct 
    
 
49. Identify the step(s) in creating a Triangle Applet that displays two triangles.  Mar k for Review (1) Points
         (Choose all correct answers)
    
   Extend Applet class to inherit all methods including paint. (*)      Override the paint method to include the triangles. (*)      Draw the triangle using the inherited fillPolygon method. (*)      Draw the 2nd triangle using the inherited fillPolygon method. (*)      Run and compile your code. (*)      None of the above. 
    
  
 Incorrect. Refer to Section 7 Lesson 5. 
    
 
50. What does it mean to override a method?
 Mar k for Review (1) Points
         It is a way to create multiple methods with the same name but different parameters.      It allows an array to contain different object types.      It restricts the privacy of the method to only be accessible from inside the same class.      It is a way of redefining methods of a parent class inside the child class, with the same name, parameters, and return type. (*) 
    
  
 Incorrect. Refer to Section 7 Lesson 5.        
1. Given the code:
String s = new String("abc");
Which of the following statements will change the length of s to the largest length? Mark for Review  (1) Points  s.trim() 
s.replace("a", "aa") 
s.substring(2) 
s.toUpperCase() 
None of the above will change the length of s. (*) 
 Correct
2. Suppose that str1 and str2 are two strings. Which of the statements or expressions are valid? Mark for Review  (1) Points  String str3 = str1 - str2; 
str1 += str2; (*) 
str1 >= str2 
Str1 -= str2; 
 Correct  3. Which of the following creates a String named Char? Mark for Review  (1) Points  char string; 
String Char; (*) 
char Char; 
char char; 
String char; 
 Correct  4. What will the following code segment output?
String s="\\\n\"\n\\\n\""; System.out.println(s); Mark for Review  (1) Points  \" \" 
""\ "" \ "" 
\ " \ " (*)
 
" \ " \ " " 
 Incorrect. Refer to Section 4 Lesson 4.  5. Consider the following code snippet 
String forest = new String("Black");  System.out.println(forest.length()); 
What is printed? Mark for Review  (1) Points  5 (*) 


Black 
Forest 
 Incorrect. Refer to Section 4 Lesson 4.  6. Given the following declaration, which line of Java code properly casts one type into another without data loss? 
int i=3,j=4; double y=2.54; Mark for Review  (1) Points
int x=(double)2.54; 
double x=i/j; 
double x=(double)(i/j); 
double x= double i/j; 
double x=(double)i/j; (*)
   Incorrect. Refer to Section 4 Lesson 3.  7. What two values can a boolean variable have? Mark for Review  (1) Points  Numbers and characters 
True and false (*) 
Relational and logic operators 
Arithmetic and logic operators 
Integers and floating point types 
 Incorrect. Refer to Section 4 Lesson 3.  8. Which of the following defines a driver class? Mark for Review  (1) Points  Contains a main method and other static methods. (*) 
Contains classes that define objects. 
Contains a main method, a package, static methods, and classes that define objects. 
None of the above. 
 Incorrect. Refer to Section 4 Lesson 2.  9. Which of the following defines an object class? Mark for Review  (1) Points  Contains a main method and other static methods. 
Contains classes that define objects. (*) 
Contains a main method, a package, static methods, and classes that define objects. 
None of the above. 
 Incorrect. Refer to Section 4 Lesson 2.  10. In the image below, identify the components. 

Mark for Review  (1) Points  A-Main Method, B-Class, C-Package 
A-Class, B-MainMethod, C-Package 
A-Package, B-Main Method, C-Class (*) 
None of the above 
 Incorrect. Refer to Section 4 Lesson 1.  11. You can return to the Eclipse Welcome Page by choosing Welcome from what menu? Mark for Review  (1) Points  File 
Edit 
Help (*) 
Close 
 Incorrect. Refer to Section 4 Lesson 1.
12. Multiple windows are used when more than one file is open in the edit area. True or False? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 4 Lesson 1.  13. What is the purpose of the Eclipse Editor Area and Views? Mark for Review  (1) Points (Choose all correct answers)   To modify elements. (*) 
To navigate a hierarchy of information. (*) 
To choose the file system location to delete a file. 
 Incorrect. Refer to Section 4 Lesson 1.  14. In Eclipse, when you run a Java Application, the results are displayed in a new window. True or False? Mark for Review  (1) Points  True 
False (*) 
 Correct
Section 5 (Answer all questions in this section) 15. What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?
for(int i = 0; i < 10; i++){<br> if(i%2 == 0) //your answer here else k+=3; } Mark for Review  (1) Points  continue; (*) 
break; 
return;
 k+=1; 
 Incorrect. Refer to Section 5 Lesson 2.  16. Updating the input of a loop allows you to implement the code with the next element rather than repeating the code always with the same element. True or false? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 5 Lesson 2.  17. When the for loop condition statement is met the construct is exited. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 5 Lesson 2.  18. Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user's input and sets it equal to a new String called input? Mark for Review  (1) Points  String input = in.next(); (*) 
String input = in.close(); 
String input = new String in.next(); 
String input = in.nextInt(); 
 Incorrect. Refer to Section 5 Lesson 1.  19. How would you use the ternary operator to rewrite this if statement? 
if (gender == "female") System.out.print("Ms."); else System.out.print("Mr."); Mark for Review  (1) Points  System.out.print( (gender == "female") ? "Mr." : "Ms." );
 
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*) 
(gender == "female") ? "Mr." : "Ms." ; 
(gender == "female") ? "Ms." : "Mr." ; 
 Correct  20. switch statements work on all input types including, but not limited to, int, char, and String. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 5 Lesson 1.  21. It is possible to throw and catch a second exception inside a catch block of code. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct  22. The following segment of code initializes a 2 dimensional array of primitive data types. True or false?
double[][] a=new double[4][5]; Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 6 Lesson 1.  23. What will be the content of the array variable table after executing the following code? 

Mark for Review  (1) Points  1 1 1 0 1 1 0 0 1 
1 0 0 0 1 0 0 0 1 
1 0 0 1 1 0 1 1 1 (*) 
0 0 1 0 1 0 1 0 0 
 Incorrect. Refer to Section 6 Lesson 1.  24. What is the output of the following segment of code?  
Mark for Review  (1) Points  321123 
642 
642246 (*) 
312213 
This code doesn't compile.

 Correct  25. What is the output of the following segment of code? 
int array[][] = {{1,2,3},{3,2,1}};  for(int i=0;i<2;i++)  for(int j=0;j<3;j++)  System.out.print(2*array[1][1]); Mark for Review  (1) Points  444444 (*) 
123321 
246642 
222222 
This code doesn't compile. 
 Incorrect. Refer to Section 6 Lesson 1.  26. Of the options below, what is the fastest run-time? Mark for Review  (1) Points

n^2 
lg(n) (*) 
n*lg(n) 
 Incorrect. Refer to Section 6 Lesson 2.  27. Which of the following is the correct lexicographical order for the conents of the int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} Mark for Review  (1) Points  {71, 1, 3, 28,29, 50, 22, 83, 1, 17} 
{83, 71, 50, 29, 28, 22, 17, 3, 1, 1} 
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
 
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3} 
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83} (*) 
 Incorrect. Refer to Section 6 Lesson 2.  28. Selection sort is efficient for large arrays. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 6 Lesson 2.  29. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct
Section 7 (Answer all questions in this section) 30. Choose the correct implementation of a public access modifier for the method divide. Mark for Review  (1) Points  divide(int a, int b, public) {return a/b;} 
public divide(int a, int b) {return a/b;} (*) 
divide(int a, int b) {public return a/b;} 
divide(public int a, public int b) {return a/b;} 
 Incorrect. Refer to Section 7 Lesson 2.  31. Which of the following could be a reason to return an object? Mark for Review  (1) Points  Because you wish to be able to use that object inside of the method. 
It has faster performance than returning a primitive type. 
The method makes changes to the object and you wish to continue to use the updated object
outside of the method. (*) 
None of the above. It is not possible to return an object. 
 Incorrect. Refer to Section 7 Lesson 2.  32. Which of the following is the correct way to code a method with a return type an object Automobile? Mark for Review  (1) Points  Automobile upgrade(String carA){  carA="Turbo";  return carA;} 
Automobile upgrade(Automobile carA){  carA.setTurbo("yes");  return carA;} (*) 
String upgrade(String carA){  carA="Turbo";  return carA;} 
upgrade(Automobile carA) Automobile{  carA.setTurbo("yes");  return carA;} 
None of the above. It is not possible to return an object. 
 Correct  33. It is possible to overload a method that is not a constructor. True or False? Mark for Review  (1) Points  True (*) 
False 
 Correct  34. Identify the error(s) in the class below. Choose all that apply.

Mark for Review  (1) Points (Choose all correct answers)   No method named min is defined. (*) 
Two methods cannot have the same name. 
The parameters must be the same for all methods with the same name. 
Private cannot be used as an access modifier. 
Final cannot be used as an access modifier. 
 Incorrect. Refer to Section 7 Lesson 2.  35. What is the Java Applet? Mark for Review  (1) Points (Choose all correct answers)   It is the virtual machine that translates Java code into a representation that the computer can understand. 
A web-based Java program that is embedded into a web browser. (*) 
A graphic visual included in Java. (*)
 There is no such thing as a Java Applet. 
 Correct  36. Why are hierarchies useful for inheritance? Mark for Review  (1) Points  They keep track of where you are in your program. 
They restrict a superclass to only have one subclass. 
They organize constructors and methods in a simplified fashion. 
They are used to organize the relationship between a superclass and its subclasses. (*) 
 Correct  37. Which of the following correctly describes an "is-a" relationship? Mark for Review  (1) Points  A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*) 
A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications. 
It restricts access to a specified segment of code. 
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. 
 Incorrect. Refer to Section 7 Lesson 4.  38. Why is it not possible to extend more than one class at a time in an inheritance hierarchy chain? Mark for Review  (1) Points  It is not necessary considering all public content is passed from super class to subclass and further to their subclass and that subclass' subclass and so on. (*) 
Because the computer cannot handle code that complex. 
To prevent confusion for the programmer. 
It is possible to extend more than one class at a time. 
 Correct
39. The following code creates an object of type Horse: Whale a=new Whale(); Mark for Review  (1) Points  True 
False (*) 
 Correct  40. A constructor is used to create objects. True or false? Mark for Review  (1) Points  True (*) 
False 
 Correct  41. The constructor method must always have at least one parameter. True or false? Mark for Review  (1) Points  True 
False (*) 
 Correct  42. The basic unit of encapsulation in Java is the primitive data type. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 7 Lesson 1.  43. What is true about the code below:
Car car1=new Car(); Car car2=new Car(); car2=car1; Mark for Review  (1) Points (Choose all correct answers)   The references car1 and car2 are pointing to two Car Objects in memory. 
The reference car2 points to an exact copy of the Car Object that car1 references. (*)
 
There are no more Car objects in memory. 
There is a Car object that car1 referenced that is now slated for removal by the garbage collector. 
There is a Car object that car2 referenced that is now slated for removal by the garbage collector. (*) 
 Incorrect. Refer to Section 7 Lesson 1.  44. The following code creates an object of type Animal. True or false? 
Animal a=new Animal(); Mark for Review  (1) Points  True (*) 
False 
 Correct  45. If an abstract class does not have implemented constructors or methods, it should be implemented as an interface instead. True or false? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 7 Lesson 5.  46. Abstract class cannot extend another abstract class. True or false? Mark for Review  (1) Points  True 
False (*) 
 Incorrect. Refer to Section 7 Lesson 5.  47. Which of the following can be declared final? Mark for Review  (1) Points  Classes 
Methods 
Local variables
 Method parameters 
All of the above (*) 
 Correct  48. A non-linear recursive method calls how many copies of itself in the recursive case? Mark for Review  (1) Points  0 

2 or more (*) 
 Correct  49. Static classes can extend their parent class. True or false? Mark for Review  (1) Points  True (*) 
False 
 Incorrect. Refer to Section 7 Lesson 3.  50. Static methods can write to instance variables. True or false? Mark for Review  (1) Points  True 
False (*) 
 Correct 
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)
  
 
1 .  The String methods equals and compareTo perform similar functions and differ in their return type. True or false?
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
   
 Correct  
  
 
2 .  Consider the following code snippet.   
What is printed?
Mark for Review (1) Points
  
  
88888 (*) 
  
88888888 
  
1010778 
  
101077810109 
  
ArrayIndexOutofBoundsException is thrown 
  
   
 Incorrect. Refer to Section 4 Lesson 4.  
  
 
3 .  What is printed by the following code segment? 
Mark for Review (1) Points
  
  
alligator (*) 
  
albatross alligator 
  
albatross 
  
a1 
  
   
 Correct  
  
 
4 .  Which of the following creates a String named Char?
Mark for Review (1) Points
  
  
char string; 
  
String Char; (*) 
  
char Char; 
  
char char; 
  
String char; 
  
   
 Incorrect. Refer to Section 4 Lesson 4.  
  
 
5 .  The following program prints "Not Equal":  
True or false?
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
   
 Correct  
    Page 1 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)
   
 
6.  Which of the following statements displays 12345?
I. System.out.println( 123 * 100 + 45); II. System.out.println("123" + 45); III. System.out.println( 12 + "345");
Mark for Review  (1) Points
         All of the above. (*) 
  
I only. 
  
I and II only. 
  
II and III only. 
  
None of the above. 
   
   
 Incorrect. Refer to Section 4 Lesson 3.  
   
 
7.  What are Java's primitive types?
Mark for Review  (1) Points
         boolean, byte, char, double, float, int, long, and short (*) 
  
boolean, byte, string, thread, int, double, long and short 
  
object, byte, string, char, float, int, long and short 
  
boolean, thread, stringbuffer, char, int, float, long and short 
  
boolean, thread, char, double, float, int, long and short 
   
   
 Correct  
   
 
8.  What is the purpose of the Eclipse Editor Area and Views?
Mark for Review  (1) Points
        (Choose all correct answers)
         To modify elements. (*) 
  
To navigate a hierarchy of information. (*) 
  
To choose the file system location to delete a file. 
   
   
 Incorrect. Refer to Section 4 Lesson 1.  
   
 
9.  You can return to the Eclipse Welcome Page by choosing Welcome from what menu?
Mark for Review  (1) Points
         File 
  
Edit 
  
Help (*) 
  
Close 
   
   
 Incorrect. Refer to Section 4 Lesson 1.  
   
 
10.  Multiple windows are used when more than one file is open in the edit area. True or False?
Mark for Review  (1) Points
         True 
  
False (*) 
   
   
 Correct  
      Page 2 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)
   
 
11.  A perspective is described as:
Mark for Review  (1) Points
         A combination of views and editors (*) 
  
A combination of views and windows 
  
A combination of editor tabs 
  
None of the above 
   
   
 Incorrect. Refer to Section 4 Lesson 1.  
   
 
12.  When you open more than one file in Eclipse the system will __________________.
Mark for Review  (1) Points
         Close the previously opened file. 
  
Use tabs to display all files open. (*) 
  
Put the new file opened in a View area only. 
  
None of the above. 
   
   
 Incorrect. Refer to Section 4 Lesson 1.  
   
 
13.  The following defines an import keyword:
Mark for Review  (1) Points
         Defines where this class lives relative to other classes, and provides a level of access control. 
  
Provides the compiler information that identifies outside classes used within the current class. (*) 
  
Precedes the name of the class. 
   
   
 Incorrect. Refer to Section 4 Lesson 2.  
   
 
14.  Which of the following defines an object class?
Mark for Review  (1) Points
         Contains a main method and other static methods. 
  
Contains classes that define objects. (*) 
  
Contains a main method, a package, static methods, and classes that define objects. 
  
None of the above. 
   
   
 Incorrect. Refer to Section 4 Lesson 2.  
    
      Section 5  (Answer all questions in this section)
   
 
15.  Why are loops useful?
Mark for Review  (1) Points
         They save programmers from having to rewrite code. 
  
They allow for repeating code a variable number of times. 
  
They allow for repeating code until a certain argument is met. 
  
All of the above. (*) 
   
   
 Incorrect. Refer to Section 5 Lesson 2.  
      Page 3 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 5  (Answer all questions in this section)
  
 
16 .  A counter used in a for loop cannot be initialized within the For loop header. True or false?
Mark for Review (1) Points
  
  
True 
  
False (*) 
  
   
 Incorrect. Refer to Section 5 Lesson 2.  
  
 
17 .  In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false?
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
   
 Correct  
  
 
18 .  How would you use the ternary operator to rewrite this if statement?   if (gender == "female") System.out.print("Ms.");
Mark for Review
else System.out.print("Mr.");
(1) Points
  
  
System.out.print( (gender == "female") ? "Mr." : "Ms." ); 
  
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*) 
  
(gender == "female") ? "Mr." : "Ms." ; 
  
(gender == "female") ? "Ms." : "Mr." ; 
  
   
 Correct  
  
 
19 .  switch statements work on all input types including, but not limited to, int, char, and String. True or false?
Mark for Review (1) Points
  
  
True 
  
False (*) 
  
   
 Correct  
  
 
20 .  Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Mark for Review (1) Points
  
  
Example A (*) 
  
Example B 
  
   
 Incorrect. Refer to Section 5 Lesson 1.  
     Page 4 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 6  (Answer all questions in this section)
   
 
21.  Suppose you misspell a method name when you call it in your program. Which of the following explains why this gives you an exception?
Mark for Review  (1) Points
         Because the parameters of the method were not met. 
  
Because the interpreter does not recognize this method since it was never initialized, the correct spelling of the method was initialized. 
  
Because the interpreter tries to read the method but when it finds the method you intended to use it crashes. 
  
This will not give you an exception, it will give you an error when the program is compiled. (*) 
   
   
 Incorrect. Refer to Section 6 Lesson 3.  
   
 
22.  Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?
Mark for Review  (1) Points
         Sequential Search 
  
Merge Sort (*) 
  
Selection Sort 
  
Binary Search 
  
All of the above 
   
   
 Incorrect. Refer to Section 6 Lesson 2.  
   
 
23.  Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false?
Mark for Review  (1) Points
         True (*) 
  
False 
   
   
 Incorrect. Refer to Section 6 Lesson 2.  
   
 
24.  Why might a sequential search be inefficient?
Mark for Review  (1) Points
         It utilizes the "divide and conquer" method, which makes the algorithm more error prone. 
  
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*) 
  
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets. 
  
It is never inefficient. 
   
   
 Incorrect. Refer to Section 6 Lesson 2.  
   
 
25.  Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false?
Mark for Review  (1) Points
         True (*) 
  
False 
   
   
 Correct  
      Page 5 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 6  (Answer all questions in this section)
  
 
26 .  Which of the following declares and initializes a one dimensional array named words of size 3 so that all entries can be Strings?
Mark for Review (1) Points
  
  
String strings=new String[3]; 
  
String[] word={"Over","the","mountain"}; (*) 
  
String[] word=new String[3]; 
  
String[] words={"Oracle","Academy"}]; 
  
   
 Incorrect. Refer to Section 6 Lesson 1.  
  
 
27 .  The following segment of code prints all five of the command line arguments entered into this program. True or false?
Mark for Review
 (1) Points
  
  
True 
  
False (*) 
  
   
 Correct  
  
 
28 .  The following creates a reference in memory named q that can refer to six different integers via an index. True or false?
int[] q = new int[8];
Mark for Review (1) Points
  
  
True 
  
False (*) 
  
   
 Incorrect. Refer to Section 6 Lesson 1.  
  
 
29 .  The following creates a reference in memory named q that can refer to eight different doubles via an index. True or false? 
double[] q = new double[8];
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
   
 Correct  
   
     Section 7  (Answer all questions in this section)
  
 
30 .  Forward thinking helps when creating linear recursive methods. True or false?
Mark for Review (1) Points
  
  
True 
  
False (*) 
  
   
 Correct  
     Page 6 of 10   
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 7  (Answer all questions in this section)
   
 
31.  A static variable is always publicly available. True or false?
Mark for Review  (1) Points
         True 
  
False (*) 
   
   
 Correct  
   
 
32.  There is only one copy a static class variable in the JVM. True or false?
Mark for Review  (1) Points
         True (*) 
  
False 
   
   
 Correct  
   
 
33.  The following statement compiles and executes. What do you know for certain? 
tree.grows(numFeet);
Mark for Review  (1) Points
         numFeet must be an int. 
  
tree must be the name of the class. 
  
grows must be the name of an instance field. 
  
grows must be the name of a method. (*) 
  
tree must be a method. 
   
   
 Incorrect. Refer to Section 7 Lesson 1.  
   
 
34.  A constructor is used to create objects. True or false?
Mark for Review  (1) Points
         True (*) 
  
False 
   
   
 Incorrect. Refer to Section 7 Lesson 1.  
   
 
35.  The basic unit of encapsulation in Java is the primitive data type. True or false?
Mark for Review  (1) Points
         True 
  
False (*) 
   
   
 Correct  
      Page 7 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 7  (Answer all questions in this section)
  
 
36 . Java's garbage collection is when all references to an object are gone, the memory used by the object is automatically reclaimed. True or false?
Mark for Review (1) Points
  
  
True (*) 
  
False 
  
  
 Correct  
  
 
37 . What value will return for j when the setValue method is called?
Mark for Review (1) Points
  
  
31 
  
32 
  
10 
  
11 (*) 
  
  
 Incorrect. Refer to Section 7 Lesson 1.  
  
 
38 . Identify the driver class that correctly initializes employees Jane and Brandon. The Employee class is below.
Mark for Review
 public class Employee { private String name;  private int age;  private double salary; public Employee(String n, int a, double s) { name = n;  age = a;  salary = s;  } //methods for this class would go here }
(1) Points
  
  
public class driver_class { public static void main(String[] args) { Employee Jane = new Employee("Jane", 48, 35.00); Employee Brandon = new Employee("Brandon", 36, 20.00);  } } (*) 
  
public class driver_class { public static void main(String[] args) { Employee("Jane", 48, 35.00); Employee("Brandon", 36, 20.00);  } } 
  
public class driver_class { public Employee{ Jane = new Employee("Jane", 48, 35.00); Brandon = new Employee("Brandon", 36, 20.00);  } } 
  
public class Employee { public class driver-class{ Employee Jane = new Employee(); Employee Brandon = new Employee();  } } 
  
  
 Incorrect. Refer to Section 7 Lesson 1.  
  
 
39 . Which of the following can be used as a parameter?
Mark for Review (1) Points
       (Choose all correct answers)
  
  
Integers (*) 
  
Strings (*) 
  
Constructors 
  
Arrays (*) 
  
Objects (*) 
  
  
 Incorrect. Refer to Section 7 Lesson 2.  
  
 
40 . Which of the following correctly defines overloading?
Mark for Review (1) Points
  
  
Having more than one constructor with the same name but different arguments. (*) 
  
Having more than one constructor with different names and the same arguments. 
  
A variable argument method that returns an array. 
  
A type of access specifier that only allows access from inside the same class. 
  
  
 Incorrect. Refer to Section 7 Lesson 2.  
     Page 8 of 10   
Test: Java Fundamentals Final Exam  Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 7  (Answer all questions in this section)
  
 
41 .  Which of the following is the definition of a constructor?
Mark for Review (1) Points
  
  
A keyword that specifies accessibility of code. 
  
A special method that is used to assign initial values to instance variables in a class. (*) 
  
A way to call a method with a variable number of arguments using an elipse. 
  
A variable in a method declaration that gets passed into the method. 
  
   
 Incorrect. Refer to Section 7 Lesson 2.  
  
 
42 .  Identify the error(s) in the class below. Choose all that apply.
Mark for Review (1) Points
       (Choose all correct answers)
  
  
No method named min is defined. (*) 
  
Two methods cannot have the same name. 
  
The parameters must be the same for all methods with the same name. 
  
Private cannot be used as an access modifier. 
  
Final cannot be used as an access modifier. 
  
   
 Incorrect. Refer to Section 7 Lesson 2.  
  
 
43 .  Which segment of code represents a correct way to call a variable argument method counter that takes in integers as its variable argument parameter?
Mark for Review (1) Points
  
  
counter(String a, int b); 
  
counter(int[] numbers); 
  
counter(1, 5, 8, 17, 11000005); (*) 
  
counter("one","two",String[] nums); 
  
   
 Incorrect. Refer to Section 7 Lesson 2.  
  
 
44 .  Which of the following show the correct UML representation of the super class Planet and its subclass Earth?
Mark for Review (1) Points
  
    
(*) 
   
 
   
 
  
None of the above. 
  
   
 Incorrect. Refer to Section 7 Lesson 4.  
  
 
45 .  Which of the following correctly describes an "is-a" relationship?
Mark for Review (1) Points
  
  
A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*) 
  
A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications. 
  
It restricts access to a specified segment of code. 
  
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. 
  
   
 Incorrect. Refer to Section 7 Lesson 4.  
     Page 9 of 10   
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 7  (Answer all questions in this section)
  
 
46 .  Why is it not possible to extend more than one class at a time in an inheritance hierarchy chain?
Mark for Review (1) Points
  
  
It is not necessary considering all public content is passed from super class to subclass and further to their subclass and that subclass' subclass and so on. (*) 
  
Because the computer cannot handle code that complex. 
  
To prevent confusion for the programmer. 
  
It is possible to extend more than one class at a time. 
  
   
 Incorrect. Refer to Section 7 Lesson 4.  
  
 
47 .  Where should the constructor for a superclass be called?
Mark for Review (1) Points
  
  
Anywhere inside the subclass. 
  
Inside the main method of the subclass. 
  
The last line in the constructor of the subclass. 
  
The first line of the constructor in the subclass. (*) 
  
The super constructor does not need to be called inside the subclass. 
  
   
 Incorrect. Refer to Section 7 Lesson 4.  
  
 
48 .  If we override the toString() method with the code below, what would be the result of printing? 
Mark for Review (1) Points
  
  
It would print the array one element at a time. The console screen would display: 0 18 215 64 11 42 
  
It would print the string returned from the method. The console screen would display: [0,18,215,64,11,42,] (*) 
  
It would print the array backwards. The console screen would display:
42 11 64 215 18 0
  
It would print the string returned from the method. The console screen would display: {0, 18, 215, 64, 11, 42} 
  
   
 Incorrect. Refer to Section 7 Lesson 5.  
  
 
49 .  Which of the following are true about abstract methods?
Mark for Review (1) Points
       (Choose all correct answers)
  
  
They cannot have a method body. (*) 
  
They must be overridden in a non-abstract subclass. (*) 
  
They must be declared in an abstract class. (*) 
  
They may contain implementation. 
  
They must be overloaded. 
  
   
 Incorrect. Refer to Section 7 Lesson 5.  
  
 
50 .  Abstract classes can be instantiated. True or false?
Mark for Review (1) Points
  
  
True 
  
False (*) 
  
   
 Incorrect. Refer to Section 7 Lesson 5.  
     Page 10 of 10    


5

1.     Why are loops useful?     Mark for Review
(1) Points
                  
          
    They save programmers from having to rewrite code.

          
    They allow for repeating code a variable number of times.

          
    They allow for repeating code until a certain argument is met.

          
    All of the above. (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
2.     In a for loop, the counter is automatically incremented after each loop iteration. True or False?     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 2.

                  
3.     What is the output of the following code segment?

int num = 7;
while(num >= 0)
{
num -= 3;
}
System.out.println(num);     Mark for Review
(1) Points
                  
          
    -2 (*)

          
    2

          
    1

          
    0

                  
              
Correct        Correct

                  
4.     What should replace the comment "//your answer here" in the code below if the code is meant to take no action when i % 2 is 0 (in other words when i is even)?

for(int i = 0; i < 10; i++){
if(i%2 == 0)
//your answer here
else
k+=3;
}     Mark for Review
(1) Points
                  
          
    k+=1;

          
    continue; (*)

          
    return;

          
    break;

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
5.     All of the following are essential to initializing a for loop, except which one?     Mark for Review
(1) Points
                  
          
    Updating the counter.

          
    Having a conditional statement.

          
    Having an if statement. (*)

          
    Initializing the iterator(i).

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
Page 1 of 3    Next    Summary


6.     What is the function of the word "break" in Java?    
Mark for Review
(1) Points
                  
          
    It exits the current loop or case statement. (*)

          
    It continues onto the next line of code.

          
    It stops the program from running.

          
    It does not exist in Java.

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 2.

                  
7.     Which of the following correctly initializes a for loop that executes 5 times?     Mark for Review
(1) Points
                  
          
    for(int i = 1; i < 5; I++)

          
    for(int i = 0; i == 6; i++)

          
    for(int i = 0; i < 5; I++)

          
    for(int i = 1; i < 6; i++) (*)

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 2.

                  
8.     How would you use the ternary operator to rewrite this if statement?

if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5;     Mark for Review
(1) Points
                  
          
    numberOfEnemies = ( skillLevel >= 5) ? 5 : 10;

          
    numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)

          
    numberOfEnemies = ( skillLevel >= 5) ? 10 : 5;

          
    numberOfEnemies = ( skillLevel > 5) ? 5 : 10;

          
    numberOfEnemies = ( skillLevel < 5) ? 10 : 5;

                  
              
Correct    Correct

                  
9.     Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?

I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y)     Mark for Review
(1) Points
                  
          
    I only

          
    II only

          
    I and III

          
    II and III

          
    I, II, and III (*)

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 1.

                  
      
10.     Which of the following are relational operators in Java?    
Mark for Review
(1) Points
                  
(Choose all correct answers)  
                  
          
    < (*)

          
    <= (*)

          
    =

          
    != (*)

          
    All of the above.

          
11.     In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 1.

                  
12.     Which of the following correctly matches the switch statement keyword to its function?     Mark for Review
(1) Points
                  
            (Choose all correct answers)  
                  
          
    if: records the user's input and sends it to the case statements to find a possible match

          
    switch: tells the compiler the value to compare the input against

          
    case: signals what code is executed if the user input matches the specified element (*)

          
    default: signals what code to execute if the input does not match any of the cases (*)

          
    switch: identifies what element will be compared to the element of the case statements to find a possible match (*)

                  

13.     Which of the following correctly initializes an instance of Scanner, called "in", that reads input from the console screen?     Mark for Review
(1) Points
                  
          
    Scanner in = Scanner(System.in);

          
    Scanner in = new Scanner("System.in");

          
    System.in in = new Scanner();

          
    Scanner in = new Scanner(System.in); (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 1.

                  
14.     The following code fragment properly implements the switch statement. True or false?

default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
System.out.println("Invalid input");     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 1.

                  
15.     What will print if the following Java code is executed?

     Mark for Review
(1) Points
                  
          
    0

          
    4

          
    3 (*)

          
    5

1) The following code fragment properly implements the switch statement. True or false?

default(input)
switch '+':
answer+=num;
break;
case '-':
answer-=num;
break;
!default
System.out.println("Invalid input");     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 1.

                  
2.     Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?

     Mark for Review
(1) Points
                  
          
    Example A (*)

          
    Example B

                  
3.     How would you use the ternary operator to rewrite this if statement?

if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms.");     Mark for Review
(1) Points
                  
          
    System.out.print( (gender == "male") ? "Mr." : "Ms." ); (*)

          
    System.out.print( (gender == "male") ? "Ms." : "Mr." );

          
    (gender == "male") ? "Ms." : "Mr." ;

          
    (gender == "male") ? "Mr." : "Ms." ;


                  
4.     Determine whether this boolean expression evaluates to true or false:
!(3 < 4 && 5 > 6 || 6 <= 6 && 7 - 1 == 6)     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect Incorrect. Refer to Section 5 Lesson 1.

                  
5.     The three logic operators in Java are:     Mark for Review
(1) Points
                  
          
    &, |, =

          
    &&, ||, ! (*)

          
    !=, =, ==

          
    &&, !=, =

6.     How would you use the ternary operator to rewrite this if statement?

if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr.");     Mark for Review
(1) Points
                  
          
    (gender == "female") ? "Ms." : "Mr." ;

          
    System.out.print( (gender == "female") ? "Mr." : "Ms." );

          
    (gender == "female") ? "Mr." : "Ms." ;

          
    System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 1.

                  
7.     The three logic operators in Java are:     Mark for Review
(1) Points
                  
          
    &&,!=,=

          
    &,|,=

          
    &&, ||, ! (*)

          
    !=,=,==

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 1.

                  
8.     How would you use the ternary operator to rewrite this if statement?

if (balance < 500)
fee = 10;
else
fee = 0;     Mark for Review
(1) Points
                  
          
    fee = ( balance > 5) ? 10 : 0;

          
    fee= ( balance < 500) ? 10 : 0; (*)

          
    fee = ( balance < 500) ? 0 : 10;

          
    fee = ( balance >= 5) ? 0 : 10;

          
    fee = ( balance >= 500) ? 10 : 0;


                  
9.     Why are loops useful?     Mark for Review
(1) Points
                  
          
    They save programmers from having to rewrite code.

          
    They allow for repeating code a variable number of times.

          
    They allow for repeating code until a certain argument is met.

          
    All of the above. (*)


                  
10.     In the code fragment below, the syntax for the for loop's initialization is correct. True or false?

public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))
{
System.out.println ("i: " + i);
}
}
}

 Mark for Review
(1) Points
                  
          
    True

          
    False (*)

11.     Which of the following is true about a do-while loop?     Mark for Review
(1) Points
                  
          
    It is a post-test loop.

          
    It is a modified while loop that allows the program to run through the loop once before testing the boolean condition.

          
    It continues looping until the condition becomes false.

          
    All of the above. (*)


                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
12.     What is the function of the word "break" in Java?     Mark for Review
(1) Points
                  
          
    It does not exist in Java.

          
    It stops the program from running.

          
    It exits the current loop or case statement. (*)

          
    It continues onto the next line of code.

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
13.     In a for loop the counter is not automatically incremented after each loop iteration. Code must be written to increment the counter. True or false?     Mark for Review
(1) Points
                  
          
    True (*)

          
    False

                  
              
Correct        Correct

                  
14.     One advantage to using a while loop over a for loop is that a while loop always has a counter. True or false?     Mark for Review
(1) Points
                  
          
    True

          
    False (*)

                  
              
Incorrect        Incorrect. Refer to Section 5 Lesson 2.

                  
15.     Which of the following correctly initializes a for loop that executes 5 times?     Mark for Review
(1) Points
                  
          
    for(int i = 1; i < 5; I++)

          
    for(int i = 0; i == 6; i++)

          
    for(int i = 1; i < 6; i++) (*)

          
    for(int i = 0; i < 5; I++)

Artikel Terkait

Life with colorful experience


EmoticonEmoticon