Wednesday, January 3, 2018

Kunci Jawaban All Quiz Oracle Academy Java Fundamental 2017 Part 14

1.     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]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        2.     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
                  
          
    0
  
          
    1
  
          
    2
  
          
    -2 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        3.     Which of the following best describes a while loop?     Mark for Review
(1) Points
                  
          
    A loop that is executed repeatedly until the conditional statement is false. (*)
  
          
    A loop that contains a counter in parenthesis with the conditional statement.
  
          
    A loop that contains a segment of code that is executed before the conditional statement is tested.
  
          
    A loop that executes the code at least one time even if the conditional statement is false.
  
                  
              
[Correct]         Correct
  
                  
        4.     What is a loop?     Mark for Review
(1) Points
                  
          
    A keyword used to skip over the remaining code.
  
          
    A set of logic that is repeatedly executed until a certain condition is met. (*)
  
          
    A segment of code that may only ever be executed once per call of the program.
  
          
    None of the above.
  
                  
              
[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
                  
          
    Initializing the iterator(i).
  
          
    Updating the counter.
  
          
    Having an if statement. (*)
  
          
    Having a conditional statement.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
6.     When the for loop condition statement is met the construct is exited. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        7.     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
  
                  
        8.     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]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        9.     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]         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.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
11.     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.
  
                  
        12.     The following prints Yes on the screen. True or false?

String Yes No
    Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        13.     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 = new String in.next();
  
          
    String input = in.next(); (*)
  
          
    String input = in.close();
  
          
    String input = in.nextInt();
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        14.     In Java, each case seqment of a switch statement requires the keyword break to avoid "falling through".     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        15.     In an if-else construct, the condition to be evaluated must be contained within parentheses. True or False?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
1.     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.
  
                  
        2.     What is a loop?     Mark for Review
(1) Points
                  
          
    A keyword used to skip over the remaining code.
  
          
    A set of logic that is repeatedly executed until a certain condition is met. (*)
  
          
    A segment of code that may only ever be executed once per call of the program.
  
          
    None of the above.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        3.     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
                  
          
    break;
  
          
    return;
  
          
    k+=1;
  
          
    continue; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        4.     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 (*)
  
                  
              
[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
                  
          
    Initializing the iterator(i).
  
          
    Having an if statement. (*)
  
          
    Updating the counter.
  
          
    Having a conditional statement.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
6.     Which of the following correctly initializes a for loop that executes 5 times?     Mark for Review
(1) Points
                  
          
    for(int i = 0; i == 6; i++)
  
          
    for(int i = 0; i < 5; I++)
  
          
    for(int i = 1; i < 6; i++) (*)
  
          
    for(int i = 1; i < 5; I++)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        7.     When the for loop condition statement is met the construct is exited. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        8.     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]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        9.     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]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        10.     Determine whether this boolean expression evaluates to true or false:

!(3 < 4 && 6 > 6 || 6 <= 6 && 7 - 2 == 6)     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
11.     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 < 500) ? 10 : 0; (*)
  
          
    fee = ( balance < 500) ? 0 : 10;
  
          
    fee = ( balance > 5) ? 10 : 0;
  
          
    fee = ( balance >= 500) ? 10 : 0;
  
          
    fee = ( balance >= 5) ? 0 : 10;
  
                  
              
[Correct]         Correct
  
                  
        12.     The three logic operators in Java are:     Mark for Review
(1) Points
                  
          
    &,|,=
  
          
    !=,=,==
  
          
    &&, ||, ! (*)
  
          
    &&,!=,=
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        13.     Which of the following correctly matches the switch statement keyword to its function?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    switch: identifies what element will be compared to the element of the case statements to find a possible match (*)
  
          
    default: signals what code to execute if the input does not match any of the cases (*)
  
          
    switch: tells the compiler the value to compare the input against
  
          
    if: records the user's input and sends it to the case statements to find a possible match
  
          
    case: signals what code is executed if the user input matches the specified element (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        14.     What will print if the following Java code is executed?

if ((5.1 > 4.3 && 6.2 < 8.4) && !(7.2 < 3.5 || 1.2 == 2.1 || 2.2 != 2.25))
System.out.print("TRUE");
else
System.out.print("FALSE");     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        15.     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 user to enter an input in the console screen and prints out a message that the user input was successfully read in.
  
          
    Because it terminates the current loop.
  
          
    Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
1.     Which line of code shows the correct way to throw an exception?     Mark for Review
(1) Points
                  
          
    throw Exception("Array index is out of bounds");
  
          
    throw new Exception("Array index is out of bounds"); (*)
  
          
    new throw Exception("Array index is out of bounds");
  
          
    throws new Exception("Array index is out of bounds");
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        2.     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
                  
          
    This will not give you an exception, it will give you an error when the program is compiled. (*)
  
          
    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.
  
                  
              
[Correct]         Correct
  
                  
        3.     Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception.     Mark for Review
(1) Points
                  
          
    True. Although errors may be more severe than exceptions they can still be handled in code the same way exceptions are.
  
          
    True. Errors and exceptions are the same objects and are interchangeable.
  
          
    False. An error is much more severe than an exception and cannot be dealt with adequately in a program. (*)
  
          
    False. Exceptions are caused by a mistake in the code and errors occur for no particular reason and therefore cannot be handled or avoided.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        4.     What does the interpreter look for when an exception is thrown?     Mark for Review
(1) Points
                  
          
    The end of the code.
  
          
    It does not look for anything. It stops interpreting your code.
  
          
    It does not look for anything. It just keeps reading through your code.
  
          
    A catch statement in the code. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        5.     What is wrong with this code?


    Mark for Review
(1) Points
                  
          
    There is nothing wrong with this code.
  
          
    It does not compile. (*)
  
          
    It is missing a semicolon.
  
          
    It gives you an out of bounds exception.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
6.     Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen?     Mark for Review
(1) Points
                  
          
    for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5); (*)
  
          
    for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5);
  
          
    for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
  
          
    System.out.println(prices[i]+5);
  
                  
              
[Correct]         Correct
  
                  
        7.     Which of the following declares and initializes a two dimensional array named values with 2 rows and 3 columns where each element is a reference to an Object?     Mark for Review
(1) Points
                  
          
    String[][] values=new String[2][3]; (*)
  
          
    String[][] values;
  
          
    String[][] values={"apples","oranges","pears"};
  
          
    String[][] values=new String[3][2];
  
                  
              
[Correct]         Correct
  
                  
        8.     What is the output of the following segment of code?


    Mark for Review
(1) Points
                  
          
    777777 (*)
  
          
    This code doesn't compile.
  
          
    456789
  
          
    987654
  
          
    555555
  
                  
              
[Correct]         Correct
  
                  
        9.     What is the output of the following segment of code?


    Mark for Review
(1) Points
                  
          
    1286864
  
          
    643432
  
          
    This code does not compile.
  
          
    666666 (*)
  
          
    262423242322
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        10.     Which of the following declares and initializes a one dimensional array that can hold 5 Object reference types?     Mark for Review
(1) Points
                  
          
    String[] array=String[4];
  
          
    String[] array=new String[5];
  
          
    Object[] array=new Object[4];
  
          
    Object array=new Object[5]; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
11.     What will array arr contain after the following code segment has been executed?

int [] arr = {5, 4, 2, 1, 0};
for (int i = 1; i < arr.length; i++)
{
arr[i - 1] += arr[i];
}     Mark for Review
(1) Points
                  
          
    None of the above.
  
          
    9, 6, 3, 1, 0 (*)
  
          
    10, 6, 3, 1, 0
  
          
    7, 3, 2, 1, 0
  
          
    9, 6, 1, 3, 0
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        12.     Which of the following declares a one dimensional array named "score" of type int that can hold 9 values?     Mark for Review
(1) Points
                  
          
    int[] score=new int[9]; (*)
  
          
    int score;
  
          
    int score=new int[9];
  
          
    int[] score;
  
                  
              
[Correct]         Correct
  
                  
        13.     The following creates a reference in memory named k that can refer to six different integers via an index. True or false?

int k[]= int[6];     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        14.     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
  
                  
              
[Correct]         Correct
  
                  
        15.     Which of the following declares and initializes a two dimensional array where each element is a reference type?     Mark for Review
(1) Points
                  
          
    char[][] words;
  
          
    String words=new String[10];
  
          
    String[][] words=new String[10][3]; (*)
  
          
    char[][] words=new char[10][4];
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
1.     It is possible to inherit from an abstract class. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        2.     Identify the step (s) in creating a Triangle Applet that displays two triangles.     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    Override the paint method to include the triangles. (*)
  
          
    Draw the 2nd triangle using the inherited fillPolygon method. (*)
  
          
    Draw the triangle using the inherited fillPolygon method. (*)
  
          
    Extend Applet class to inherit all methods including paint. (*)
  
          
    Run and compile your code. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
  
                  
        3.     Which of the following is a goal of the object model?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    Providing modular code that can be reused by other programs or classes. (*)
  
          
    Protecting information and limiting other classes' ability to change or corrupt data. (*)
  
          
    Concealing implementation. (*)
  
          
    Data abstraction. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
  
                  
        4.     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} (*)
  
          
    Integer easyArray ... (int elems) {//code}
  
          
    String easyArray(... String elems) {//code}
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.
  
                  
        5.     Following good programming guidelines, what access modifier should be used for the class fields in the following situation?

A car insurance company wants to create a class named Customer that stores all data for a specified customer including the fields: vehicle information, policy information, and a credit card number.     Mark for Review
(1) Points
                  
          
    public
  
          
    protected
  
          
    private (*)
  
          
    default
  
          
    All of the above
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.
6.     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("one","two",String[] nums);
  
          
    counter(1, 5, 8, 17, 11000005); (*)
  
          
    counter(int[] numbers);
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.
  
                  
        7.     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.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 4.
  
                  
        8.     Which of the following correctly defines a superclass (or parent class)?     Mark for Review
(1) Points
                  
          
    A keyword that allows or restricts access to data and methods.
  
          
    A class that inherits methods and fields from a more general class.
  
          
    A class that passes down its methods to more specialized classes. (*)
  
          
    The most specific class of a hierarchy system of classes.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 4.
  
                  
        9.     Why are hierarchies useful for inheritance?     Mark for Review
(1) Points
                  
          
    They organize constructors and methods in a simplified fashion.
  
          
    They keep track of where you are in your program.
  
          
    They restrict a superclass to only have one subclass.
  
          
    They are used to organize the relationship between a superclass and its subclasses. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 4.
  
                  
        10.     A class can only have one constructor. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 1.
11.     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]         Correct
  
                  
        12.     The following code creates an object of type Animal. True or false?

Animal a=new Animal();     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        13.     Static methods can return any object type. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        14.     The final keyword makes a static variable act like a constant. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        15.     You can create static class methods inside any Java class. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct   
1.     Eclipse does not provide views to help you navigate a hierarchy of information. True or False?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 1.
  
                  
        2.     Two 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
  
                  
              
[Correct]         Correct
  
                  
        3.     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
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 1.
  
                  
        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=""; (*)
  
          
    String s;
  
          
    s="s";
  
          
    String s=new String("s"); (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 4.
  
                  
        5.     Which of the following statements declares a String object called name?     Mark for Review
(1) Points
                  
          
    String name; (*)
  
          
    String name
  
          
    double name;
  
          
    int name;
  
                  
              
[Correct]         Correct
6.     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. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 4.
  
                  
        7.     Which of the following examples of Java code is not correct?     Mark for Review
(1) Points
                  
          
    char c='r';
  
          
    boolean b=1; (*)
  
          
    int x=6;
  
          
    double d=4.5;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        8.     Which line of code does not assign 3.5 to the variable x?     Mark for Review
(1) Points
                  
          
    double x=3.5
  
          
    3.5=x; (*)
  
          
    x=3.5;
  
          
    x=7.0/2.0;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        9.     Which of the following is a legal identifier?     Mark for Review
(1) Points
                  
          
    apple (*)
  
          
    boolean
  
          
    grand Total
  
          
    7up
  
                  
              
[Correct]         Correct
  
                  
        10.     What are Java's primitive types?     Mark for Review
(1) Points
                  
          
    boolean, thread, stringbuffer, char, int, float, long and short
  
          
    boolean, byte, string, thread, int, double, long and short
  
          
    boolean, thread, char, double, float, int, long and short
  
          
    object, byte, string, char, float, int, long and short
  
          
    boolean, byte, char, double, float, int, long, and short (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
11.     What is the output of the following lines of code?

int j=7,k=5,m=8,result;
result=j-k%3*m;
System.out.println(result);     Mark for Review
(1) Points
                  
          
    0
  
          
    16
  
          
    2
  
          
    -9 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        12.     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.
  
                  
              
[Correct]         Correct
  
                  
        13.     When importing another package into a class you must import the entire package as well as the package classes that will be called. True or False?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 2.
  
                  
        14.     The following defines a class keyword:     Mark for Review
(1) Points
                  
          
    Provides the compiler information that identifies outside classes used within the current class.
  
          
    Precedes the name of the class. (*)
  
          
    Defines where this class lives relative to other classes, and provides a level of access control.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 2.
  
                  
        15.     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.
  
                  
              
[Correct]         Correct
              
1.     When the for loop condition statement is met the construct is exited. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        2.     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]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        3.     All of the following are essential to initializing a for loop, except which one?     Mark for Review
(1) Points
                  
          
    Having an if statement. (*)
  
          
    Initializing the iterator(i).
  
          
    Updating the counter.
  
          
    Having a conditional statement.
  
                  
              
[Correct]         Correct
  
                  
        4.     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
  
                  
        5.     Which of the following correctly initializes a for loop that executes 5 times?     Mark for Review
(1) Points
                  
          
    for(int i = 0; i == 6; i++)
  
          
    for(int i = 1; i < 5; I++)
  
          
    for(int i = 1; i < 6; i++) (*)
  
          
    for(int i = 0; i < 5; I++)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
6.     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.
  
                  
        7.     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 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        8.     The following prints Yes on the screen. True or false?


    Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        9.     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
  
                  
              
[Correct]         Correct
  
                  
        10.     Which of the following could be a reason to use a switch statement in a Java program?     Mark for Review
(1) Points
                  
          
    Because it terminates the current loop.
  
          
    Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
  
          
    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.
  
          
    Because it allows the code to be run through until a certain conditional statement is true.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
11.     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
  
                  
              
[Correct]         Correct
  
                  
        12.     The six relational operators in Java are:     Mark for Review
(1) Points
                  
          
    >,<,==,!=,<=,>= (*)
  
          
    >,<,=,!,<=,>=
  
          
    >,<,=,!=,=<,=>
  
          
    >,<,=,!=,<=,>=
  
                  
              
[Correct]         Correct
  
                  
        13.     The six relational operators in Java are:     Mark for Review
(1) Points
                  
          
    >, <, ==, !=, <=, >= (*)
  
          
    >, <, =, !=, <=, >=
  
          
    >, <, =, !, <=, >=
  
          
    >, <, =, !=, =<, =>
  
                  
              
[Correct]         Correct
  
                  
        14.     In an if-else construct, the condition to be evaluated must be contained within parentheses. True or False?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        15.     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]         Incorrect. Refer to Section 5 Lesson 1.
  
                1.     What is wrong with this code?


    Mark for Review
(1) Points
                  
          
    It is missing a semicolon.
  
          
    There is nothing wrong with this code.
  
          
    It does not compile. (*)
  
          
    It gives you an out of bounds exception.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        2.     What exception message indicates that a variable may have been mispelled somewhere in the program?     Mark for Review
(1) Points
                  
          
    variableName cannot be resolved to a variable (*)
  
          
    method methodName(int) is undefined for the type className
  
          
    Syntax error, insert ";" to complete statement
  
          
    All of the above
  
                  
              
[Correct]         Correct
  
                  
        3.     If an exception is thrown by a method, where can the catch for the exception be?     Mark for Review
(1) Points
                  
          
    The catch can be in the method that threw the exception or in any other method that called the method that threw the exception. (*)
  
          
    The catch must be in the method that threw the exception.
  
          
    The catch must be immediately after the throw.
  
          
    There does not need to be a catch in this situation.
  
                  
              
[Correct]         Correct
  
                  
        4.     A logic error occurs if an unintentional semicolon is placed at the end of a loop initiation because the interpreter reads this as the only line inside the loop, a line that does nothing. Everything that follows the semicolon is interpreted as code outside of the loop. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        5.     What are exceptions used for in Java?     Mark for Review
(1) Points
                  
          
    Helping the interpreter compile code quicker and handle user interfaces.
  
          
    Exceptions have no use, they are just a part of the Java language.
  
          
    Making the program easier to use for the user and reducing the possibilities of errors occuring.
  
          
    Correcting mistakes made in your code and handling extraordinary cases. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
6.     The following array declaration is valid:

int[] y = new int[5];     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        7.     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]         Correct
  
                  
        8.     The following array declaration is valid. True or false?

int[] y = new int[5];     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        9.     What is the output of the following segment of code if the command line arguments are "apples oranges pears"?


    Mark for Review
(1) Points
                  
          
    3 (*)
  
          
    This code does not compile.
  
          
    2
  
          
    1
  
          
    0
  
                  
              
[Correct]         Correct
  
                  
        10.     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
                  
          
    This code doesn't compile.
  
          
    246642
  
          
    444444 (*)
  
          
    222222
  
          
    123321
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                11.     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]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        12.     Which of the following declares and initializes a two dimensional array where each element is a reference type?     Mark for Review
(1) Points
                  
          
    char[][] words=new char[10][4];
  
          
    String[][] words=new String[10][3]; (*)
  
          
    String words=new String[10];
  
          
    char[][] words;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        13.     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
  
                  
              
[Correct]         Correct
  
                  
        14.     Which of the following declares and initializes a two dimensional array named values with 2 rows and 3 columns where each element is a reference to an Object?     Mark for Review
(1) Points
                  
          
    String[][] values=new String[3][2];
  
          
    String[][] values=new String[2][3]; (*)
  
          
    String[][] values;
  
          
    String[][] values={"apples","oranges","pears"};
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        15.     The following creates a reference in memory named y that can refer to five different integers via an index. True or false?

int[] y = new int[5];     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                1.     Which of the following are true about abstract methods?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    They must be overloaded.
  
          
    They must be overridden in a non-abstract subclass. (*)
  
          
    They cannot have a method body. (*)
  
          
    They may contain implementation.
  
          
    They must be declared in an abstract class. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
  
                  
        2.     What allows Java to correctly and automatically determine which method to invoke based on the type of object being referred to at the time the method is called?     Mark for Review
(1) Points
                  
          
    Dynamic Method Dispatch (*)
  
          
    Abstract classes
  
          
    Polymorphism
  
          
    Inheritance
  
                  
              
[Correct]         Correct
  
                  
        3.     Is there a difference between overriding a method and overloading a method?     Mark for Review
(1) Points
                  
          
    Yes. Overriding is done in the subclass and allows for redefining a method inherited from the superclass and overloading is done within a class and allows for multiple methods with the same name. (*)
  
          
    Yes. Overriding is done within a single class and overloading is done through a series of superclasses and their subclasses.
  
          
    No, they are the same.
  
          
    Yes. Overriding allows for the creation of an array of different object types and overloading restricts an array to only contain the same object types.
  
                  
              
[Correct]         Correct
  
                  
        4.     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. 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. (*)
  
          
    Yes. A subclass inherits full access to all contents of its super class.
  
          
    No. Nothing inherited by the super class can be changed in the subclass.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 4.
  
                  
        5.     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.
  
                  
              
[Correct]         Correct
6.     An access modifier is a keyword that allows subclasses to access methods, data, and constructors from their parent class. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        7.     Static classes are designed as thread safe class instances. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 3.
  
                  
        8.     A static variable is always publicly available. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 3.
  
                  
        9.     Public static variables can't have their value reset by other classes. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 3.
  
                  
        10.     The following code is a good example of using the this reference. True or false?


    Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 1.
11.     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
                  
          
    0.571, 13 (*)
  
          
    1.75, 13
  
          
    0.571, 21
  
          
    1.75, 21
  
                  
              
[Correct]         Correct
  
                  
        12.     If the return type from a method is boolean then 2.5 is a valid return value. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 1.
  
                  
        13.     It is possible to return an object from a method. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        14.     Which of the following can be used as a parameter?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    Arrays (*)
  
          
    Integers (*)
  
          
    Objects (*)
  
          
    Constructors
  
          
    Strings (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.
  
                  
        15.     Following good programming guidelines, what access modifier should be used for the class fields in the following situation?

A car insurance company wants to create a class named Customer that stores all data for a specified customer including the fields: vehicle information, policy information, and a credit card number.     Mark for Review
(1) Points
                  
          
    public
  
          
    protected
  
          
    private (*)
  
          
    default
  
          
    All of the above
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.

Artikel Terkait

Life with colorful experience

2 komentar


EmoticonEmoticon