Wednesday, January 3, 2018

Kunci Jawaban All Quiz Oracle Academy Java Fundamental 2017 Part 13

  What will the following code segment output?
             Mark for Review
(1) Points
            "\\" (*)
            "\\\"
            \"\\\\\"
            "\\\\\"

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

3.         Consider the following code snippet. What is printed?

String river = new String("Hudson"); System.out.println(river.length());      Mark for Review
(1) Points
            8
            7
            Hudson
            river
            6 (*)

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

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

6.         Which of the two diagrams below illustrate the general form of a Java program?


 Mark for Review

(1) Points
            Example A
            Example B (*)

7.         When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false?        Mark for Review
(1) Points
            True
            False (*)

8.         What two values can a boolean variable have?           Mark for Review
(1) Points
            Relational and logic operators
            Arithmetic and logic operators
            True and false (*)
            Numbers and characters
            Integers and floating point types

9.         Which line of Java code assigns the value of 5 raised to the power of 8 to a?          Mark for Review
(1) Points
            int a=Math.pow(5,8);
            double a=Math.pow(5,8); (*)
            double a=15^8;
            int a=Math.pow(8,5);
            double a=pow(8,5);

10.       What is the output of the following lines of code?

int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result);      Mark for Review
(1) Points
            -42
            2 (*)
            6
            0

11.       What will the method methodA print to the screen?

 Mark for Review
(1) Points
            15
            6
            3
            18 (*)

12.       Write a declaration statement that will hold a number like 2.541.     Mark for Review
(1) Points
            float number; (*)
            boolean number;
            char number;
            int number;

13.       For every opening curly brace { there must be a closing curly brace} or the program will not compile without error. True or False?   Mark for Review
(1) Points
            True (*)
            False

14.       You can return to the Eclipse Welcome Page by choosing Welcome from what menu?       Mark for Review
(1) Points
            Close
            Edit
            File
            Help (*)

15.       Tabs are used when more than one file is open in the edit area. True or False?         Mark for Review
(1) Points
            True (*)
            False

1.         Consider the following:

You are writing a class and are using a global variable. Inside a method you declare a local variable with the same name as the global variable.

This programming style is poor because inside the method the global variable will have precedence over the local variable with the same name.

True or false?  Mark for Review
(1) Points
            True
            False (*)

2.         Which of the following statements correctly assigns "3 times 10 to the 4th power" to the variable number?          Mark for Review
(1) Points
            double number=3(e4);
            double number=3*10e4;
            double number=3*10^4;
            double number=3e4; (*)

3.         Which line of code does not assign 3.5 to the variable x?      Mark for Review
(1) Points
            3.5=x; (*)
            x=7.0/2.0;
            double x=3.5
            x=3.5;

4.         A local variable has precedence over a global variable in a Java method. True or false?       Mark for Review
(1) Points
            True (*)
            False

5.         What does the following program output?

 Mark for Review

(1) Points
            "total cost: " 48
            total cost: 48
            "total cost: " 40
            total cost: + 40
            total cost: 40 (*)

6.         For every opening curly brace { there must be a closing curly brace} or the program will not compile without error. True or False?   Mark for Review
(1) Points
            True (*)
            False

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

8.         What symbols are required for a compiler to ignore a comment?       Mark for Review
(1) Points
            /*/
            /*
            */
            // (*)

9.         The following program prints "Equal". True or false?

Mark for Review
(1) Points
            True
            False (*)

10.       Suppose that s1 and s2 are two strings. Which of the statements or expressions are valid?  Mark for Review
(1) Points
                                    (Choose all correct answers)
            String s3 = s1 + s2; (*)
            String s3 = s1 - s2;
            s1.compareTo(s2); (*)
            int m = s1.length(); (*)
            s1 <= s2

11.       Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false?     Mark for Review
(1) Points
            True (*)
            False

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

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

14.       The following defines a class keyword:         Mark for Review
(1) Points
            Precedes the name of the class. (*)
            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.

15.       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 (*)

1.         Match each of the following literals ('x', 10, 10.2, 100L, "hello") with its respective data type.       Mark for Review
(1) Points
            char, boolean, float, long, String
            char, double, int, long, String
            char, int, long, float, String
            boolean, byte, int, long, Short
            char, int, double, long, String (*)

2.         Which line of Java code will assign the value of the square root of 11 to a variable named a?         Mark for Review
(1) Points
            int a=Math.sqrt(11);
            double a=11^(1/2);
            double a=Math.sqrt*11;
            double a=Math.sqrt(11); (*)
            double a=sqrt(11);

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

4.         Consider the following:

You are writing a class and are using a global variable. Inside a method you declare a local variable with the same name as the global variable.

This programming style is poor because inside the method the global variable will have precedence over the local variable with the same name.

True or false?  Mark for Review
(1) Points
            True
            False (*)

5.         Select the declaration and initialization statement that will hold the letter J.            Mark for Review
(1) Points
            String letter='J';
            char letter='J'; (*)
            int letter='J';
            float letter='J';

6.         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 (*)

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

8.         Eclipse provides views to help you navigate a hierarchy of information. True or False?       Mark for Review
(1) Points
            True (*)
            False

9.         The == operator can be used to compare two String objects. The result is always true if the two strings are identical. True or false?     Mark for Review
(1) Points
            True
            False (*)

10.       Consider the following code snippet

String forest = new String("Black");
System.out.println(forest.length());

What is printed?          Mark for Review
(1) Points
            Forest
            7
            6
            Black
            5 (*)

11.       The following program prints "Equal". True or false?

             Mark for Review
(1) Points
            True (*)
            False

12.       The following defines a package keyword:    Mark for Review
(1) Points
            Provides the compiler information that identifies outside classes used within the current class.
            Defines where this class lives relative to other classes, and provides a level of access control. (*)
            Precedes the name of the class.

13.       Which of the two diagrams below illustrate the general form of a Java program?

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

14.       Which of the two diagrams below illustrate the general form of a Java program?

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

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.

1.         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 (*)

2.         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 (*)

3.         What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
                                    (Choose all correct answers)
            To choose the file system location to delete a file.
            To modify elements. (*)
            To navigate a hierarchy of information. (*)

4.         The following defines an import keyword:    Mark for Review
(1) Points
            Precedes the name of the class.
            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. (*)

5.         The following defines a package keyword:    Mark for Review
(1) Points
            Precedes the name of the class.
            Provides the compiler information that identifies outside classes used within the current class.
            Defines where this class lives relative to other classes, and provides a level of access control. (*)

6.         The following defines a class keyword:         Mark for Review
(1) Points
            Defines where this class lives relative to other classes, and provides a level of access control.
            Precedes the name of the class. (*)
            Provides the compiler information that identifies outside classes used within the current class.

7.         The following defines a class keyword:         Mark for Review
(1) Points
            Provides the compiler information that identifies outside classes used within the current class.
            Defines where this class lives relative to other classes, and provides a level of access control.
            Precedes the name of the class. (*)

8.         The following code is an example of creating a String reference:

String s;

True or false?  Mark for Review
(1) Points
            True (*)
            False

9.         Which of the following statements declares a String object called name?     Mark for Review
(1) Points
            String name; (*)
            String name
            double name;
            int name;

10.       Given the code below, which of the following would equate to true?

String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
 Mark for Review
(1) Points
                                                         
                                    (Choose all correct answers)
            s1 == s2 (*)
            s3.equals(s1) (*)
            s1.equals(s2) (*)
            s1 = s2
            s3 == s1

11.       Which line of Java code will assign the value of the square root of 11 to a variable named a?         Mark for Review
(1) Points
            double a=11^(1/2);
            double a=sqrt(11);
            double a=Math.sqrt(11); (*)
            double a=Math.sqrt*11;
            int a=Math.sqrt(11);

12.       Which line of Java code assigns the value of 5 raised to the power of 8 to a?          Mark for Review
(1) Points
            int a=Math.pow(5,8);
            int a=Math.pow(8,5);
            double a=pow(8,5);
            double a=15^8;
            double a=Math.pow(5,8); (*)

13.       Which line of Java code properly calculates the area of a triangle using A=1/2(b)(h) where b and h are Java primitive integers?           Mark for Review
(1) Points
            double A=1/2bh;
            double A=(double)1/(double)2*b*h; (*)
            double A=(double)(1/2)*b*h;
            double A=1/2*b*h;

14.       What is the output of the following lines of code?

int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result);      Mark for Review
(1) Points
            0.175
            280
            4.375
            0 (*)

15.       Which of the following is not a legal name for a variable?    Mark for Review
(1) Points
            theLastValueButONe
            zero
            year2000
            2bad (*)

1.         What is the purpose of the Eclipse Editor Area and Views? Mark for Review
(1) Points
                                    (Choose all correct answers)
            To modify elements. (*)
            To choose the file system location to delete a file.
            To navigate a hierarchy of information. (*)

2.         A _______________ is used to organize Java related files.   Mark for Review
(1) Points
            Project
            Collection
            Package (*)
            Workspace

3.         A workspace can have one or more stored projects. True or false?    Mark for Review
(1) Points
            True (*)
            False

4.         Which of the two diagrams below illustrate the general form of a Java program?


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

5.         The following defines a class keyword:         Mark for Review
(1) Points
            Precedes the name of the class. (*)
            Provides the compiler information that identifies outside classes used within the current class.
            Defines where this class lives relative to other classes, and provides a level of access control.

6.         The following defines a package keyword:    Mark for Review
(1) Points
            Provides the compiler information that identifies outside classes used within the current class.
            Defines where this class lives relative to other classes, and provides a level of access control. (*)
            Precedes the name of the class.

7.         Which of the two diagrams below illustrate the general form of a Java program?

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

8.         Examine the following code:


What is the value of variable x?          Mark for Review
(1) Points
            14
            2 (*)
            6
            2.5

9.         Which of the following is not correct Java code?      Mark for Review
(1) Points
            double x=Math.pow; (*)
            double x=Math.sqrt(16);
            double x=Math.pow(3,4)*5.0;
            double x=Math.PI*5.0;

10.       What is the output of the following lines of code?

int j=7,k=5,m=8,result;
result=j/m*k;
System.out.println(result);      Mark for Review
(1) Points
            0.175
            280
            4.375
            0 (*)

11.       What is the output of the following lines of code?

int j=6,k=8,m=2,result;
result=j-k%3*m;
System.out.println(result);      Mark for Review
(1) Points
            -42
            0
            2 (*)
            6

12.       What two values can a boolean variable have?           Mark for Review
(1) Points
            Arithmetic and logic operators
            Integers and floating point types
            Numbers and characters
            Relational and logic operators
            True and false (*)

13.       What is printed by the following code segment?


 Mark for Review
(1) Points
            \\\\\\\\\\\\\\
            \\\\
            \\\\\\\ (*)
            \\

14.       Declaring and instantiating a String is much like any other type of variable. However, once instantiated, they are final and cannot be changed. True or false?     Mark for Review
(1) Points
            True (*)
            False

15.       Consider the following code snippet.




What is printed?          Mark for Review
(1) Points
            AtlanticPacificIndianArcticSouthern
            Code does not compile
            87658
            55555
            ArrayIndexOutofBoundsException is thrown (*)
1.     The String methods equals and compareTo perform the exact same function. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 4.
  
                  
        2.     Consider the following code snippet.



What is printed?     Mark for Review
(1) Points
                  
          
    ArrayIndexOutofBoundsException is thrown
  
          
    yr (*)
  
          
    Cayrbniz
  
          
    ay
  
          
    CayrbnizCayrbniz
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 4.
  
                  
        3.     Consider the following code snippet. What is printed?

String river = new String("Hudson"); System.out.println(river.length());     Mark for Review
(1) Points
                  
          
    river
  
          
    7
  
          
    Hudson
  
          
    6 (*)
  
          
    8
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 4.
  
                  
        4.     Which of the following is not correct Java code?     Mark for Review
(1) Points
                  
          
    double x=Math.PI*5.0;
  
          
    double x=Math.sqrt(16);
  
          
    double x=Math.pow; (*)
  
          
    double x=Math.pow(3,4)*5.0;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        5.     Which of the following examples of Java code is not correct?     Mark for Review
(1) Points
                  
          
    double d=4.5;
  
          
    boolean b=1; (*)
  
          
    char c='r';
  
          
    int x=6;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
6.     Select the declaration and initialization statement that will hold the letter J.     Mark for Review
(1) Points
                  
          
    int letter='J';
  
          
    char letter='J'; (*)
  
          
    float letter='J';
  
          
    String letter='J';
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        7.     What does the following program output?


    Mark for Review
(1) Points
                  
          
    "total cost: " 40
  
          
    "total cost: " 48
  
          
    total cost: + 40
  
          
    total cost: 48
  
          
    total cost: 40 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        8.     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
                  
          
    double x=i/j;
  
          
    double x=(double)(i/j);
  
          
    double x= double i/j;
  
          
    double x=(double)i/j; (*)
  
          
    int x=(double)2.54;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 3.
  
                  
        9.     In Eclipse, when you run a Java Application, the results may be displayed in the Console View. True or False?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        10.     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]         Incorrect. Refer to Section 4 Lesson 1.
11.     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
  
                  
        12.     The following defines a package keyword:     Mark for Review
(1) Points
                  
          
    Provides the compiler information that identifies outside classes used within the current class.
  
          
    Defines where this class lives relative to other classes, and provides a level of access control. (*)
  
          
    Precedes the name of the class.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 2.
  
                  
        13.     When importing another package into a class you must import only the package classes that will be called and not the entire package. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 2.
  
                  
        14.     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.
  
          
    Precedes the name of the class.
  
          
    Provides the compiler information that identifies outside classes used within the current class. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 4 Lesson 2.
  
                  
        15.     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]         Incorrect. Refer to Section 4 Lesson 2.
  
                1.     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.
  
                  
        2.     The six relational operators in Java are:     Mark for Review
(1) Points
                  
          
    >, <, =, !=, =<, =>
  
          
    >, <, ==, !=, <=, >= (*)
  
          
    >, <, =, !, <=, >=
  
          
    >, <, =, !=, <=, >=
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        3.     What is the difference between the symbols = and == ?     Mark for Review
(1) Points
                  
          
    The symbol = is used in if statements and == is used in loops.
  
          
    The symbol == is used to assign values to variables and the = is used in declarations.
  
          
    The = is use to assign values to variables and the == compares values. (*)
  
          
    There is no difference.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        4.     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) ? 10 : 5;
  
          
    numberOfEnemies = ( skillLevel > 5) ? 5 : 10;
  
          
    numberOfEnemies = ( skillLevel >= 5) ? 5 : 10;
  
          
    numberOfEnemies = ( skillLevel > 5) ? 10 : 5; (*)
  
          
    numberOfEnemies = ( skillLevel < 5) ? 10 : 5;
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        5.     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.nextInt();
  
          
    String input = in.next(); (*)
  
          
    String input = in.close();
  
          
    String input = new String in.next();
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
6.     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
  
                  
        7.     The three logic operators in Java are:     Mark for Review
(1) Points
                  
          
    !=,=,==
  
          
    &,|,=
  
          
    &&, ||, ! (*)
  
          
    &&,!=,=
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 1.
  
                  
        8.     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
  
                  
        9.     Which of the following are types of loops in Java?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    do-while (*)
  
          
    while (*)
  
          
    for (*)
  
          
    if/else
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
  
                  
        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 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
11.     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.
  
                  
        12.     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.
  
                  
        13.     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.
  
                  
        14.     The syntax below represents a valid initialization of a for loop counter. True or False?

public class ForLoop {
 public static void main (String args[])
 {
  for (int i=10; i <20; i++)
  {System.out.println("i: "+i); }
 }
}
    Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        15.     What is the function of the word "break" in Java?     Mark for Review
(1) Points
                  
          
    It stops the program from running.
  
          
    It exits the current loop or case statement. (*)
  
          
    It continues onto the next line of code.
  
          
    It does not exist in Java.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 5 Lesson 2.
1.     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 interpreter does not recognize this method since it was never initialized, the correct spelling of the method was initialized.
  
          
    This will not give you an exception, it will give you an error when the program is compiled. (*)
  
          
    Because the interpreter tries to read the method but when it finds the method you intended to use it crashes.
  
          
    Because the parameters of the method were not met.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        2.     Which of the following could be a reason to throw an exception?     Mark for Review
(1) Points
                  
          
    You have a fatal error in your program.
  
          
    To make the user interface harder to navigate.
  
          
    To eliminate exceptions from disrupting your program. (*)
  
          
    You have encountered a Stack Overflow Error.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        3.     Which of the following correctly matches the symbol with its function?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    == (two equal signs) compares values of primitive types such as int or char. (*)
  
          
    .equals() compares the value of non-primitive objects. (*)
  
          
    == (two equal signs) compares the memory location of non-primitive objects. (*)
  
          
    = (single equals sign) compares the value of primitive types such as int or char.
  
          
    == (two equal signs) compares the values of non-primitive objects.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        4.     If an exception has already been thrown, what will the interpreter read next in the program?     Mark for Review
(1) Points
                  
          
    The user input.
  
          
    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.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
  
                  
        5.     Which of the following would be a correct way to handle an index out of bounds exception?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    Throw the exception that prints out an error message. There is no need to have the catch handle the exception if it has already been thrown.
  
          
    Do nothing, it will fix itself.
  
          
    Throw the exception and catch it. In the catch, set the index to the index of the array closest to the one that was out of bounds. (*)
  
          
    Rewrite your code to avoid the exception by not permititng the use of an index that is not inside the array. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
6.     Which of the following statements print every element of the one dimensional array prices to the screen?     Mark for Review
(1) Points
                  
          
    for(int i=1; i <= prices.length; i++){System.out.println(prices[i]);}
  
          
    for(int i=0; i <= prices.length; i++){System.out.println(prices[i]);}
  
          
    for(int i=0; i < prices.length; i++){System.out.println(prices[i]);} (*)
  
          
    System.out.println(prices.length);
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        7.     What is the output of the following segment of code?


    Mark for Review
(1) Points
                  
          
    1111
  
          
    This code doesn't compile.
  
          
    11 (*)
  
          
    111
  
          
    321111
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        8.     What is the output of the following segment of code if the command line arguments are "apples oranges pears"?


    Mark for Review
(1) Points
                  
          
    oranges
  
          
    pears (*)
  
          
    This code does not compile.
  
          
    args
  
          
    apples
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        9.     Which of the following declares a one dimensional array name scores of type int that can hold 14 values?     Mark for Review
(1) Points
                  
          
    int[] scores=new scores int[14];
  
          
    int score= new int[14];
  
          
    int scores;
  
          
    int[] scores=new int[14]; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        10.     What is the output of the following segment of code?


    Mark for Review
(1) Points
                  
          
    643432
  
          
    1286864
  
          
    This code does not compile.
  
          
    666666 (*)
  
          
    262423242322

     11.     Which of the following declares and initializes a one dimensional array named values of size 5 so that all entries contain 1?     Mark for Review
(1) Points
                  
          
    int[] values={1};
  
          
    int[] values={1,1,1,1,1}; (*)
  
          
    int values[]={1,1,1,1,1,1};
  
          
    int values={1,1,1,1,1};
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        12.     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 (*)
  
          
    222222
  
          
    246642
  
          
    This code doesn't compile.
  
          
    123321
  
                  
              
[Correct]         Correct
  
                  
        13.     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
  
                  
        14.     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.
  
                  
        15.     What is the output of the following segment of code if the command line arguments are "apples oranges pears"?


    Mark for Review
(1) Points
                  
          
    1
  
          
    This code does not compile.
  
          
    0
  
          
    3 (*)
  
          
    2
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
1.     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
  
                  
        2.     What is wrong with this code?


    Mark for Review
(1) Points
                  
          
    It does not compile. (*)
  
          
    It is missing a semicolon.
  
          
    There is nothing wrong with this code.
  
          
    It gives you an out of bounds exception.
  
                  
              
[Correct]         Correct
  
                  
        3.     Which of the following could be a reason to throw an exception?     Mark for Review
(1) Points
                  
          
    To eliminate exceptions from disrupting your program. (*)
  
          
    You have a fatal error in your program.
  
          
    To make the user interface harder to navigate.
  
          
    You have encountered a Stack Overflow Error.
  
                  
              
[Correct]         Correct
  
                  
        4.     What does it mean to catch an exception?     Mark for Review
(1) Points
                  
          
    It means to handle it. (*)
  
          
    It means there was never an exception in your code.
  
          
    It means you have fixed the error.
  
          
    It means to throw it.
  
                  
              
[Correct]         Correct
  
                  
        5.     A computer company has one million dollars to give as a bonus to the employees, and they wish to distribute it evenly amongst them.

The company writes a program to calculate the amount each employee receives, given the number of employees.

Unfortunately, the employees all went on strike before they heard about the bonus. This means that the company has zero employees.

What will happen to the program if the company enters 0 into the employment number?     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    The programmers will have proven their worth in the company because without them the company wrote faulty code.
  
          
    An unfixable error will occur.
  
          
    An exception will occur because it is not possible to divide by zero. (*)
  
          
    The program will calculate that each employee will receive zero dollars because there are zero employees.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 2.
6.     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[] words=new String[3];
  
          
    String[] words={"Oracle","Academy"}];
  
          
    String[] words={"Over","the","mountain"}; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        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.     After execution of the following statement, which of the following are true?

int number[] = new int[5];     Mark for Review
(1) Points
                  
          
    number[0] is undefined
  
          
    number[4] is null
  
          
    number.length() is 6
  
          
    number[2] is 0 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        9.     double array[] = new double[8];

After execution of this statement, which of the following are true?     Mark for Review
(1) Points
                  
          
    array[4] is null
  
          
    array.length is 8 (*)
  
          
    array[2] is 8
  
          
    array[0] is undefined
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        10.     The following creates a reference in memory named z that can refer to seven different doubles via an index. True or false?

double z[] = new double[7];     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
11.     Which of the following declares and initializes a one dimensional array that can hold 5 Object reference types?     Mark for Review
(1) Points
                  
          
    Object[] array=new Object[4];
  
          
    String[] array=new String[5];
  
          
    String[] array=String[4];
  
          
    Object array=new Object[5]; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        12.     What is the output of the following segment of code?


    Mark for Review
(1) Points
                  
          
    555555
  
          
    456789
  
          
    This code doesn't compile.
  
          
    987654
  
          
    777777 (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                  
        13.     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
  
                  
        14.     Which of the following declares and initializes a two dimensional array where each element is a reference type?     Mark for Review
(1) Points
                  
          
    String[][] words=new String[10][3]; (*)
  
          
    String words=new String[10];
  
          
    char[][] words=new char[10][4];
  
          
    char[][] words;
  
                  
              
[Correct]         Correct
  
                  
        15.     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[] name=String[8];
  
          
    String names=new String[8];
  
          
    String[] name=new Strings[8];
  
          
    String[] names=new String[8]; (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 6 Lesson 1.
  
                1.     Which of the following correctly defines a subclass (or child class)?     Mark for Review
(1) Points
                  
          
    The most general class of a hierarchy system.
  
          
    A class that passes down its methods to more specialized classes.
  
          
    A class that inherits methods and fields from a more general class. (*)
  
          
    A keyword that allows or restricts access to data and methods.
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 4.
  
                  
        2.     If you inherit a class, you do not inherit the class' constructors. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        3.     Methods are generally declared as public so other classes may use them. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        4.     Static classes can't return instances of the parent class when the parent class uses a private constructor. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 3.
  
                  
        5.     You can use an inner static class to return an instance of its outer class container. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
6.     You can create static class methods inside any Java class. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        7.     Which of the following could be a reason to need to pass an object into a method?     Mark for Review
(1) Points
                  
          
    Easier access to the information contained within the object.
  
          
    The ability to make changes to an object inside of the method.
  
          
    Comparing two objects.
  
          
    All of the above. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 2.
  
                  
        8.     It is possible to have more than one constructor with the same name in a class, but they must have different parameters. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        9.     You are assigned to write a method that compares two objects of type Career. One requirement of your assignment is to have your method compare the "greatestPossibleSalary" instance data of Career objects. The "greatestPossibleSalary" field is data type int.

What would be the best return type from your compare method?     Mark for Review
(1) Points
                  
          
    Career, because if it returns the highest paying Career object it will be able to use the same method later to compare other aspects of Career objects. (*)
  
          
    Array, because it can store the most information.
  
          
    Integer, because it is the easiest to code with.
  
          
    String, because is should return a string of the name of the career that is highest paying because none of the other information of the career matters.
  
                  
              
[Correct]         Correct
  
                  
        10.     Which of the following can be declared final?     Mark for Review
(1) Points
                  
          
    Classes
  
          
    Methods
  
          
    Local variables
  
          
    Method parameters
  
          
    All of the above (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
11.     If a class is immutable then it must be abstract. True or false?     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
  
                  
        12.     Identify the step (s) in creating a Triangle Applet that displays two triangles.     Mark for Review
(1) Points
                  
            (Choose all correct answers)   
                  
          
    Extend Applet class to inherit all methods including paint. (*)
  
          
    Draw the 2nd triangle using the inherited fillPolygon method. (*)
  
          
    Run and compile your code. (*)
  
          
    Override the paint method to include the triangles. (*)
  
          
    Draw the triangle using the inherited fillPolygon method. (*)
  
                  
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 5.
  
                  
        13.     A class always has a constructor. True or false?     Mark for Review
(1) Points
                  
          
    True (*)
  
          
    False
  
                  
              
[Correct]         Correct
  
                  
        14.     Which of the following creates a class named Diver with one constructor, and 2 instance variables maxDepth and certified?     Mark for Review
(1) Points
                  
      
  
(*) float
    boolean
driver(foat boolean)
              
              
[Incorrect]         Incorrect. Refer to Section 7 Lesson 1.
  
                  
        15.     The following code creates an object of type Animal:
Animal a;     Mark for Review
(1) Points
                  
          
    True
  
          
    False (*)
   

Artikel Terkait

Life with colorful experience

1 komentar so far

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);

0
2
16
-9 (*)


EmoticonEmoticon