Wednesday, January 3, 2018

Kunci Jawaban All Quiz Oracle Academy Java Fundamental 2017 Part 17

1.         A final static variable can change at runtime. True or false?  Mark for Review
(1) Points
            True
            False (*)

2.         Static classes can have different access specifiers than the parent class. True or false?         Mark for Review
(1) Points
            True (*)
            False

3.         Static classes can exist as inner classes. True or false?           Mark for Review
(1) Points
            True (*)
            False

4.         Which of the following correctly describes an "is-a" relationship?    Mark for Review
(1) Points
            It restricts access to a specified segment of code.
            A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)
            A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.
            A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.

5.         Why are hierarchies useful for inheritance?    Mark for Review
(1) Points
            They are used to organize the relationship between a superclass and its subclasses. (*)
            They restrict a superclass to only have one subclass.
            They keep track of where you are in your program.
            They organize constructors and methods in a simplified fashion.

6.         Which of the following correctly describes the use of the keyword super?   Mark for Review
(1) Points
            A keyword that signals the end of a program.
            A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)
            A keyword that restricts access to only inside the same class.
            A keyword that allows access from anywhere.

7.         What is Polymorphism?          Mark for Review
(1) Points
            A way of redefining methods with the same return type and parameters.
            A way to create multiple methods with the same name but different parameters.
            A class that cannot be initiated.
            The concept that a variable or reference can hold multiple types of objects. (*)

8.         What is the Java keyword final used for in a program?         Mark for Review
(1) Points
            It permits redefining methods of a parent class inside the child class, with the same name, parameters, and return type.
            It permits access to the class variables and methods from anywhere.
            There is no such keyword in Java.
            It restricts a class from being extendable and restricts methods from being overridden. (*)
            It terminates the program.

9.         Identify the correct way to declare an abstract class. Mark for Review
(1) Points
            public class abstract ClassName(...)
            public abstract class ClassName{...} (*)
            public abstract ClassName(...)
            abstract public class ClassName{...}

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

11.       The basic unit of encapsulation in Java is the primitive data type. True or false?      Mark for Review
(1) Points
            True
            False (*)

12.       Consider:

public class MyClass{
public MyClass()
{/*code*/}
// more code...}

To instantiate MyClass, what would you write?        Mark for Review
(1) Points
            MyClass m = new MyClass;
            MyClass m = MyClass();
            MyClass m = MyClass;
            MyClass m = new MyClass(); (*)

13.       Which of the following can be used as a parameter? Mark for Review
(1) Points
                                    (Choose all correct answers)
            Strings (*)
            Integers (*)
            Objects (*)

            Constructors
            Arrays (*)

14.       Which segment of code represents a correct way to define a variable argument method?    Mark for Review
(1) Points
            Integer easyArray ... (int elems) {//code}
            String easyArray(String ... elems) {//code} (*)
            String ... easyArray(String elems) {//code}
            String easyArray(... String elems) {//code}

15.       Identify the error(s) in the class below. Choose all that apply
 Mark for Review
(1) Points
            Two methods cannot have the same name.
            Final cannot be used as an access modifier.
            Private cannot be used as an access modifier.
            No method named min is defined. (*)
            The parameters must be the same for all methods with the same name.

1.         Which of the following would be most beneficial for this scenario?

Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In an attempt to get organized, Joe wants to create a program that will store his textbooks in one group of books, but he wants to make each book type the subject of the book (i.e. MathBook is a book). How could he store these different subject books into a single array?

 Mark for Review
(1) Points
            By ignoring the subject type and initializing all the book as objects of type Book.
            Using polymorphism. (*)
            By overriding the methods of Book.
            This is not possible. Joe must find another way to collect the books.

2.         Abstract classes cannot implement interfaces. True or false? Mark for Review
(1) Points
            True
            False (*)

3.         If Oak extends Tree, it is possible to declare an object such that

Tree grandfatherT = new Oak();

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

4.         Which segment of code correctly defines a method that contains two objects of class Tree as parameters?     Mark for Review
(1) Points
            void bloom(Tree pine, Tree oak) {//code here } (*)
            Tree bloom (pine, oak) {//code here }
            void bloom, Tree pine, Tree oak {//code here }
            None of the above, objects cannot be passed as parameters.

5.         Consider the following:

There is a method A that calls method B. Method B is a variable argument method.

With this, which of the following are true?    Mark for Review
(1) Points
                                                         
                                    (Choose all correct answers)
            Method A can invoke method B twice, each time with a different number of arguments. (*)
            A compliler error will result since method B does not know how large an array to create when it is invoked by method A.
            When invoked, method B creates an array to store some or all of the arguments passed to it from method A. (*)
            All of the above.

6.         Which of the following is a possible way to overload constructors? Mark for Review
(1) Points
(*)

7.         Identify the driver class that correctly initializes employees Jane and Brandon. The Employee class is below.

public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}          Mark for Review
(1) Points

            public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane", 48, 35.00);
Employee Brandon = new Employee("Brandon", 36, 20.00);
}
} (*)
            public class driver_class {
public static void main(String[] args) {
Employee("Jane", 48, 35.00);
Employee("Brandon", 36, 20.00);
}
}
            public class driver_class {
public Employee{
Jane = new Employee("Jane", 48, 35.00);
Brandon = new Employee("Brandon", 36, 20.00);
}
}
            public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}

8.         What is wrong with the following class declaration?

class Account{
private int number;
private String name;
public Account;
}          Mark for Review
(1) Points
            There is nothing wrong.
            The constructor method has no definition. (*)
            Classes cannot include mixed data types.
            Classes cannot include strings.

9.         The basic unit of encapsulation in Java is the primitive data type. True or false?      Mark for Review
(1) Points
            True
            False (*)

10.       Static methods can return any object type. True or false?      Mark for Review
(1) Points
            True (*)
            False

11.       Static classes can extend their parent class. True or false?     Mark for Review
(1) Points
            True (*)
            False

12.       Non-final static class variables should be private to prevent changes from other classes. True or false?            Mark for Review
(1) Points
            True (*)
            False

13.       What is encapsulation?           Mark for Review
(1) Points
            A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.
            A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*)
            A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom.
            A keyword that allows or restricts access to data and methods.

14.       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
            No. Nothing inherited by the super class can be changed in the subclass.
            Yes. Any variable passed through inheritance can be changed, but private methods cannot.
            Yes. A subclass inherits full access to all contents of its super class.
            No. A private variable can only be modified by the same class with which it is declared regardless of its inheritance. (*)

15.       Which of the following demonstrates the correct way to create an applet Battlefield?        Mark for Review
(1) Points
            public class Applet extends Battlefield{...}
            public class Battlefield(Applet){...}
            public Applet Battlefield{...}
            public class Battlefield extends Applet{...} (*)

1.         What keyword is used to inherit a superclass?           Mark for Review
(1) Points
            extends (*)
            public
            this
            new

2.         It is possible to extend a class that already exists in Java, such as the Applet class. True or false?   Mark for Review
(1) Points
            True (*)
            False

3.         Why are hierarchies useful for inheritance?    Mark for Review
(1) Points
            They are used to organize the relationship between a superclass and its subclasses. (*)
            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.

4.         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. (*)
            No, they are the same.

            Yes. Overriding is done within a single class and overloading is done through a series of superclasses and their subclasses.

            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.

5.         It is possible to inherit from an abstract class. True or false? Mark for Review
(1) Points
            True (*)
            False

6.         If Sandal extends Shoe, it is possible to declare an object such that

Sandal s = new Shoe();           Mark for Review
(1) Points
            True
            False (*)

7.         Static classes are designed as thread safe class instances. True or false?       Mark for Review
(1) Points
            True
            False (*)

8.         Static classes can extend any class in their class path. True or false? Mark for Review
(1) Points
            True (*)
            False

9.         Static classes can extend their parent class. True or false?     Mark for Review
(1) Points
            True (*)
            False

10.       Which segment of code correctly defines a method that contains two objects of class Tree as parameters?     Mark for Review
(1) Points
            void bloom(Tree pine, Tree oak) {//code here } (*)
            Tree bloom (pine, oak) {//code here }
            void bloom, Tree pine, Tree oak {//code here }
            None of the above, objects cannot be passed as parameters.

11.       Which of the following is the correct way to code a method with a return type an object Automobile?            Mark for Review
(1) Points

            Automobile upgrade(String carA){
carA="Turbo";
return carA;
}

            Automobile upgrade(Automobile carA){
carA.setTurbo("yes");
return carA;
} (*)

            String upgrade(String carA){
carA="Turbo";
return carA;
}

            upgrade(Automobile carA) Automobile{
carA.setTurbo("yes");
return carA;
}

            None of the above. It is not possible to return an object.

12.       Choose the correct implementation of a public access modifier for the method divide.       Mark for Review
(1) Points
            divide(int a, int b, public) {return a/b;}
            divide(public int a, public int b) {return a/b;}
            public int divide(int a, int b) {return a/b;} (*)
            divide(int a, int b) {public return a/b;}

13.       Which constructor code populates the instance variables of the class correctly?       Mark for Review
(1) Points
(*)

14.       What value will return for j when the setValue method is called?
 Mark for Review
(1) Points
            10
            31
            32
            11 (*)

15.       What is wrong with the following class declaration?


  Mark for Review
(1) Points
            There is no constructor method and you have to make a constructor method.
            There is nothing wrong. (*)
            Classes cannot include strings.
            Classes cannot include mixed data types.

1.         Which of the following keywords are used to access the instance variables of an object from within the class code for that object?      Mark for Review
(1) Points
            private
            public
            this (*)
            protected

2.         The following code creates an object of type Animal:
Animal a;         Mark for Review
(1) Points
            True
            False (*)

3.         What is wrong with the following class declaration?

class Account{
private int number;
private String name;
public Account;
}          Mark for Review
(1) Points
            The constructor method has no definition. (*)
            There is nothing wrong.
            Classes cannot include mixed data types.
            Classes cannot include strings.

4.         Where should the constructor for a superclass be called?      Mark for Review
(1) Points
            The first line of the constructor in the subclass. (*)
            The last line in the constructor of the subclass.
            The super constructor does not need to be called inside the subclass.
            Inside the main method of the subclass.
            Anywhere inside the subclass.

5.         Which of the following is the proper way to set the public variable length of the super class equal to 5 from inside the subclass?        Mark for Review
(1) Points
            super.length() = 5
            super.length(5)
            super.length = 5 (*)
            super(length = 5)

6.         Which of the following correctly describes the use of the keyword super?   Mark for Review
(1) Points
            A keyword that restricts access to only inside the same class.
            A keyword that signals the end of a program.
            A keyword that allows subclasses to access methods, data, and constructors from their parent class. (*)
            A keyword that allows access from anywhere.

7.         Abstract classes can be instantiated. True or false?    Mark for Review
(1) Points
            True
            False (*)

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

9.         Abstract classes cannot implement interfaces. True or false? Mark for Review
(1) Points
            True
            False (*)

10.       There is only one copy a static class variable in the JVM. True or false?       Mark for Review
(1) Points
            True (*)
            False

11.       A final static variable can change at runtime. True or false?  Mark for Review
(1) Points
            True
            False (*)

12.       Which of the following access modifiers doesn't work with a static variable?          Mark for Review
(1) Points
            default
            public
            private
            protected
            friendly (*)

13.       How is it possible for overloading to work?   Mark for Review
(1) Points
            Java Virtual Machine searches until it finds a constructor name and argument type match. (*)
            The interpreter doesn't care what you name your constructors.
            The code has to be declared as private.
            There is no such thing as overloading.

14.       Which of the following could be a reason to return an object?          Mark for Review
(1) Points
            Because you wish to be able to use that object inside of the method.
            It has faster performance than returning a primitive type.
            The method makes changes to the object and you wish to continue to use the updated object outside of the method. (*)
            None of the above. It is not possible to return an object.

15.       Identify the error(s) in the class below. Choose all that apply
 Mark for Review
(1) Points
            Final cannot be used as an access modifier.
            No method named min is defined. (*)
            Private cannot be used as an access modifier.
            Two methods cannot have the same name.
            The parameters must be the same for all methods with the same name.

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

2.         Identify the error(s) in the class below. Choose all that apply
 Mark for Review
(1) Points
            No method named min is defined. (*)
            The parameters must be the same for all methods with the same name.
            Final cannot be used as an access modifier.
            Two methods cannot have the same name.
            Private cannot be used as an access modifier.

3.         Which segment of code represents a correct way to call a variable argument method counter that takes in integers as its variable argument parameter?           Mark for Review
(1) Points
            counter(String a, int b);
            counter(int[] numbers);
            counter("one","two",String[] nums);
            counter(1, 5, 8, 17, 11000005); (*)

4.         The return value of a method can only be a primitive type and not an object. True or false?            Mark for Review
(1) Points
            True
            False (*)

5.         All objects, in Java, are created using int. True or false?        Mark for Review
(1) Points
            True
            False (*)

6.         Which of the following is true?          Mark for Review
(1) Points
            Instance variable names may only contain letters and digits.
            int is the name of a class available in the package java.lang.
            In Java, a method declared public generates a compilation error.
            The more comments in a program, the faster the program runs.
            A class always has a constructor (possibly automatically supplied by the java compiler). (*)

7.         If an abstract class does not have implemented constructors or methods, it should be implemented as an interface instead. True or false?     Mark for Review
(1) Points
            True (*)
            False

8.         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
            Inheritance
            Dynamic Method Dispatch (*)
            Polymorphism
            Abstract classes

9.         What is the Java keyword final used for in a program?         Mark for Review
(1) Points
            It terminates the program.
            It permits redefining methods of a parent class inside the child class, with the same name, parameters, and return type.
            It restricts a class from being extendable and restricts methods from being overridden. (*)
            It permits access to the class variables and methods from anywhere.
            There is no such keyword in Java.

10.       Which of the following correctly defines a superclass (or parent class)?       Mark for Review
(1) Points
            A class that inherits methods and fields from a more general class.
            A keyword that allows or restricts access to data and methods.
            The most specific class of a hierarchy system of classes.
            A class that passes down its methods to more specialized classes. (*)

11.       It is possible for a subclass to be a superclass. True or false? Mark for Review
(1) Points
            True (*)
            False

12.       Which of the following correctly describes an "is-a" relationship?    Mark for Review
(1) Points
            It restricts access to a specified segment of code.
            A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.
            A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)
            A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.

13.       Static methods can write to instance variables. True or false?           Mark for Review
(1) Points
            True
            False (*)

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

15.       Static classes can have different access specifiers than the parent class. True or false?         Mark for Review
(1) Points
            True (*)
            False

1.         According to the following class declaration, runSpeed can be modified in class Cat. True or false

public class Tiger extends Cat{
public int runSpeed;
}          Mark for Review
(1) Points
            True
            False (*)

2.         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
            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.
            Yes. Any variable passed through inheritance can be changed, but private methods cannot.
            Yes. A subclass inherits full access to all contents of its super class.

3.         It is possible to extend a class that already exists in Java, such as the Applet class. True or false?   Mark for Review
(1) Points
            True (*)
            False

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

5.         The following statement compiles and executes. What do you know for certain?

tree.grows(numFeet);  Mark for Review
(1) Points
            tree must be a method.
            grows must be the name of a method. (*)
            numFeet must be an int.
            tree must be the name of the class.
            grows must be the name of an instance field.

6.         A constructor must have the same name as the class where it is declared. True or false?      Mark for Review
(1) Points
            True (*)
            False

7.         If a class is immutable then it must be abstract. True or false?           Mark for Review
(1) Points
            True
            False (*)

8.         Which of the following is a goal of the object model?           Mark for Review
(1) Points
                                    (Choose all correct answers)
            Data abstraction. (*)
            Protecting information and limiting other classes' ability to change or corrupt data. (*)
            Providing modular code that can be reused by other programs or classes. (*)
            Concealing implementation. (*)

9.         Identify the step (s) in creating a Triangle Applet that displays two triangles.          Mark for Review
(1) Points
                                    (Choose all correct answers)
            Draw the triangle using the inherited fillPolygon method. (*)
            Draw the 2nd triangle using the inherited fillPolygon method. (*)
            Extend Applet class to inherit all methods including paint. (*)
            Override the paint method to include the triangles. (*)
            Run and compile your code. (*)

10.       How is it possible for overloading to work?   Mark for Review
(1) Points
            The code has to be declared as private.
            There is no such thing as overloading.
            The interpreter doesn't care what you name your constructors.
            Java Virtual Machine searches until it finds a constructor name and argument type match. (*)

11.       A team is working on a coding project. They desire that all portions of their code should have access to the classes that they write. What access modifier should be used for each class?     Mark for Review
(1) Points
            public (*)
            protected
            private
            default
            All of the above

12.       It is possible to overload a method that is not a constructor. True or False?  Mark for Review
(1) Points
            True (*)
            False

13.       A static variable is always publicly available. True or false?  Mark for Review
(1) Points
            True
            False (*)

14.       Static methods can read instance variables. True or false?     Mark for Review
(1) Points
            True
            False (*)

15.       Static classes can exist as stand alone classes. True or false? Mark for Review
(1) Points
            True
            False (*)                  
1.      What are Java's simple types?              
          
    boolean, byte, char, double, float, int, long, and short (*)
boolean, byte, string, thread, int, double, long and short
object, byte, string, char, float, int, long and short
boolean, thread, stringbuffer, char, int, float, long and short
boolean, thread, char, double, float, int, long and short

2.     Which of the following are relational operators in Java?     (Choose all correct answers)  
                          
    < (*)      
    <= (*)      
    =      
    != (*)      
    All of the above.

3.     What is the output of the following lines of code?
int j=6,k=4,m=12,result;
result=j/m*k;
System.out.println(result);                              
    2      
    0 (*)      
    48      
    24

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

5.     What does the following program output?



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

6.      What is the result when the following code segment is compiled and executed?

int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p);  
                          
    Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"  
    4.0 is displayed (*)      
    2.2 is displayed      
    5.656854249492381 is displayed      
    ClassCastException
7.     Determine whether this boolean expression evaluates to true or false:

!(3<4&&6>6||6<=6&&7-2==6)  
    True (*)    False
8.      In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?    
      
    True    False (*)

                  
              
9.     Which of the two diagrams below illustrate the general form of a Java program?
                  
    Example A

          
    Example B (*)

10.      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?    
              
True (*)        False

11.      When the For loop condition statement is met the construct is exited. True or false?    
    True        False (*)
      
12.      You can return to the Eclipse Welcome Page by choosing Welcome from what menu?    
                          
    File      
    Edit      
    Help (*)      
    Close

13.      In Eclipse, when you run a Java Application, where may the results display?    
  
    Editor Window      
    Console View (*)      
    Debug View      
    Task List      
    None of the above
  
14.      A combination of views and editors are referred to as _______________.    
                          
    A workspace
A physical location
A perspective (*)
All of the above
      
15.      What are the Eclipse Editor Area and Views used for?(Choose all correct answers)  
                  
To modify elements. (*)
To navigate a hierarchy of information. (*)
To choose the file system location to delete a file.
16.     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 function doNothin is:
public double doNothing(int n)
{
n = n + 8;
return (double) 12/n;
}  
                  
    1.75, 13
0.571, 21
1.75, 21
0.571, 13 (*)

                  
              
                          
17.     Updating the input of a loop allows you to implement the code with the next element rather than repeating the code always with the same element. True or false?  
    True (*)        False
          
18.     One advantage to using a WHILE loop over a FOR loop is that a WHILE loop always has a counter. True or false?        True    False (*)
          
19.      Which of the following could be a reason to use a switch statement in a Java program?                              
Because it allows the code to be run through until a certain conditional statement is true.
Because it allows the program to run certain segments of code and neglect to run others based on the input given. (*)
Because it terminates the current loop.
Because it allows the user to enter an input in the console screen and prints out a message that the user input was successfully read in.
  
20.     In Java, an instance field referenced using the this keyword generates a compilation error. True or false?    
    True        False (*)
                  
21.     Consider

public class YourClass{ public YourClass(int i){/*code*/} // more code...}

To instantiate YourClass, what would you write?    
    YourClass y = new YourClass();
YourClass y = new YourClass(3); (*)
YourClass y = YourClass(3);
YourClass y = YourClass();
None of the above.
      
22.      A constructor must have the same name as the class it is declared within. True or false?                      
    True (*)        False
          
23.     Which of the following keywords are used to control access to the member of a class?  
          
    default      
    public (*)      
    class      
    All of the above.      
    None of the above.
24.      Which of the following creates a method that compiles with no errors in the class?    
      
  

(*)

          
  


          
    All of the above.

          
    None of the above

25.     The following code creates an Object of type Horse. True or false?
Whale a=new Whale();    
    True        False (*)


26.      What operator do you use to call an object's constructor method and create a new object?                      
          
    +          
    new (*)      
    instanceOf
          
27.     Which of the following declares a one dimensional array name scores of type int that can hold 14 values?  
      
int scores;
int[] scores=new int[14]; (*)
int[] scores=new int[14];
int score= new int[14]

28.      Which of the following statements is not a valid array declaration?      
    int number[];
float []averages;      
    double marks[5];
counter int[]; (*)
                  
29.     What is the output of the following segment of code if the command line arguments are "a b c d e f"?
  
    1      
    3      
    5      
    6 (*)
  
      
30.      Which of the following declares a one dimensional array named names of size 8 so that all entries can be Strings?  
      
    String names=new String[8];      
    String[] name=new Strings[8];      
    String[] names=new String[8]; (*)      
    String[] name=String[8];
                  
31.      What will the following code segment output?

String s="\\\\\
System.out.println(s);  
      
    "\\\\\"      
    \\\\\\\\      
    \\      
    \\\\ (*)
                  
32.      Consider the following code snippet.

What is printed?     Mark for Review
(1) Points
                  
          
    88888 (*)  
    88888888      
    1010778      
    101077810109      
    ArrayIndexOutofBoundsException is thrown

                  
  

                  
33.      Given the code

String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);

Which of the following would equate to false?    
    s1 == s2      
    s1 = s2      
    s3 == s1 (*)      
    s1.equals(s2)      
    s3.equals(s1)

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

if (balance < 500)
fee = 10;
else
fee = 0;  
              
          
    fee = ( balance < 500) ? 0 : 10;      
    fee= ( balance < 500) ? 10 : 0; (*)      
    fee = ( balance >= 5) ? 0 : 10;      
    fee = ( balance >= 500) ? 10 : 0;      
    fee = ( balance > 5) ? 10 : 0;
  
35.      If an exception is thrown by a method, where can the catch for the exception be?  
          
    There does not need to be a catch in this situation.      
    The catch must be in the method that threw the exception.      
    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 immediately after the throw.

36.      Choose the best response to this statement: An error can be handled by throwing it and catching it just like an exception.          
    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. (*      
    True. Although errors may be more severe than exceptions they can still be handled in code the same way exceptions are.    False. Exceptions are caused by a mistake in the code and errors occur for no particular reason and therefore cannot be handled or avoided.
      
37.      Which of the following could be a reason to throw an exception?    
                          
    To eliminate exceptions from disrupting your program. (*)      
    You have a fatal error in your program.
    You have encountered a Stack Overflow Error.
To make the user interface harder to navigate.
      
38.     Suppose you misspell a method name when you call it in your program. Which of the following explains why this gives you an exception?  
          
    Because the parameters of the method were not met.      
    Because the interpreter does not recognize this method since it was never initialized, the correct spelling of the method was initialized.      
    Because the interpreter tries to read the method but when it finds the method you intended to use it crashes.      
    This will not give you an exception, it will give you an error when the program is compiled. (*)

                  
  
                  
39.      Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass SqueakyRobot?  
                  
    Robot.needOil(SqueakyRobot);      
    SqueakyRobot.needOil();      
    super.needOil(); (*)      
    needOil(Robot);
      
40.      Why are hierarchies useful for inheritance?              
          
    They keep track of where you are in your program.      
    They restrict a superclass to only have one subclass.  
    They organize constructors and methods in a simplified fashion.      
    They are used to organize the relationship between a superclass and its subclasses. (*)

41.     It is possible for a subclass to be a superclass. True or false?    
  
    True (*)        False
  
42.     Static methods can write to instance variables. True or false?  
    True        False (*)
  
43.     Static classes are designed as thread safe class instances. True or false?      
    True        False (*)
          
44.     Public static variables can't have their value reset by other classes. True or false?    
    True    False (*)

45.      Choose the correct implementation of a public access modifier for the method divide.                              
    divide(int a, int b, public) {return a/b;}      
    public divide(int a, int b) {return a/b;} (*)      
    divide(int a, int b) {public return a/b;}      
    divide(public int a, public int b) {return a/b;}
                  
46.      Which of the following specifies accessibility to variables, methods, and classes?  
    Methods      
    Parameters      
    Overload constructors      
    Access specifiers (*)

47.      Which segment of code represents a correct way to call a variable argument method counter that takes in integers as its variable argument parameter?  
          
    counter(String a, int b);      
    counter(int[] numbers);
counter(1, 5, 8, 17, 11000005); (*)      
    counter("one","two",String[] nums);
                  
48.      Which of the following can be declared final?      
    Classes      
    Methods      
    Local variables      
    Method parameters      
    All of the above (*)

  

          
49.     Which of the following would be most beneficial for this scenario?

Joe is a college student who has a tendency to lose his books. Replacing them is getting costly. In an attempt to get organized, Joe wants to create a program that will store his textbooks in one group of books, but he wants to make each book type the subject of the book (i.e. MathBook is a book). How could he store these different subject books into a single array?

    By ignoring the subject type and initializing all the book as objects of type Book.      
    By overriding the methods of Book.      
    Using polymorphism. (*)      
    This is not possible. Joe must find another way to collect the books.
  
50.      What is Polymorphism?    
          
    A way of redefining methods with the same return type and parameters.      
    A way to create multiple methods with the same name but different parameters.  
    A class that cannot be initiated.      
    The concept that a variable or reference can hold multiple types of objects. (*)
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

     Section 4
     (Answer all questions in this section)
                         
          1.      The following code is an example of instantiating a String object:

String str = String( "Hello" );

True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          2.      The following program prints "Not Equal":



True or false?      Mark for Review
(1) Points
                         
               
True (*)
    
               
False
    
                         
                              Correct
    
                         
          3.      Consider the following code snippet.



What is printed?      Mark for Review
(1) Points
                         
               
Cayrbniz
    
               
CayrbnizCayrbniz
    
               
yr (*)
    
               
ay
    
               
ArrayIndexOutofBoundsException is thrown
    
                         
                              Correct
    
                         
          4.      What will the following code segment output?

String s="\\\n\"\n\\\n\"";
System.out.println(s);     Mark for Review
(1) Points
                         
               
\" \"
    
               
""\
""
\
""
    
               
\
"
\
" (*)
    
               
"
\
"
\
"
"
    
                         
                              Correct
    
                         
          5.      Given the code

String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);

Which of the following would equate to false?      Mark for Review
(1) Points
                         
               
s1 == s2
    
               
s1 = s2
    
               
s3 == s1 (*)
    
               
s1.equals(s2)
    
               
s3.equals(s1)
    
                         
                              Correct
  
Section 4
     (Answer all questions in this section)
                         
          6.      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.
    
                         
                              Correct
    
                         
          7.      Which of the following defines an object class?      Mark for Review
(1) Points
                         
               
Contains a main method and other static methods.
    
               
Contains classes that define objects. (*)
    
               
Contains a main method, a package, static methods, and classes that define objects.
    
               
None of the above.
    
                         
                              Correct
    
                         
          8.      Which of the following is not a legal name for a variable?      Mark for Review
(1) Points
                         
               
2bad (*)
    
               
zero
    
               
theLastValueButONe
    
               
year2000
    
                         
                              Correct
    
                         
          9.      Which of the following is the name of a Java primitive data type?      Mark for Review
(1) Points
                         
               
Object
    
               
Rectangle
    
               
double (*)
    
               
String
    
                         
                              Correct
    
                         
          10.      A workspace can not have more than one stored projects. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
  
    Section 4
     (Answer all questions in this section)
                         
          11.      Multiple windows are used when more than one file is open in the edit area. True or False?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Incorrect. Refer to Section 4 Lesson 1.
    
                         
          12.      What symbols are required for a compiler to ignore a comment?      Mark for Review
(1) Points
                         
               
// (*)
    
               
/*
    
               
*/
    
               
/*/
    
                         
                              Correct
    
                         
          13.      You need to _______________ Java code to generate a .class file      Mark for Review
(1) Points
                         
               
Collect
    
               
Compile (*)
    
               
Package
    
               
Assemble
    
                         
                              Correct
    
                         
          14.      What is the purpose of the Eclipse Editor Area and Views?      Mark for Review
(1) Points
                         
               (Choose all correct answers)    
                         
               
To modify elements. (*)
    
               
To navigate a hierarchy of information. (*)
    
               
To choose the file system location to delete a file.
    
                         
                              Correct
    
                         

                         
     Section 5
     (Answer all questions in this section)
                         
          15.      switch statements work on all input types including, but not limited to, int, char, and String. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
  
Section 5
     (Answer all questions in this section)
                         
          16.      How would you use the ternary operator to rewrite this if statement?

if (gender == "female") System.out.print("Ms.");
else
System.out.print("Mr.");      Mark for Review
(1) Points
                         
               
System.out.print( (gender == "female") ? "Mr." : "Ms." );
    
               
System.out.print( (gender == "female") ? "Ms." : "Mr." ); (*)
    
               
(gender == "female") ? "Mr." : "Ms." ;
    
               
(gender == "female") ? "Ms." : "Mr." ;
    
                         
                              Incorrect. Refer to Section 5 Lesson 1.
    
                         
          17.      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
    
                         
                              Incorrect. Refer to Section 5 Lesson 1.
    
                         
          18.      In the code fragment below, the syntax for the for loop's initialization is correct. True or false?

public class ForLoop {
public static void main (String args[])
{
for ((int 1=10) (i<20) (i++))<br> {System.out.Println ("i: "+i); }
}
}     Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Incorrect. Refer to Section 5 Lesson 2.
    
                         
          19.      When the for loop condition statement is met the construct is exited. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          20.      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. (*)
    
                         
                              Correct
  
Section 6
     (Answer all questions in this section)
                         
          21.      Which of the following statements add all of the elements of the one dimensional array prices, and then prints the sum to the screen?      Mark for Review
(1) Points
                         
               
int total = 0;
for(int i = 0; i
total+=prices[i];

    
               
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(total); (*)
    
               
int total = 0;
for(int i = 1; i
total = total+prices[i];
System.out.println(prices);
    
               
int total = 0;
for(int i = 0; i
total+=prices[i];
System.out.println(prices);
    
                         
                              Correct
    
                         
          22.      What is the output of the following segment of code if the command line arguments are "a b c d e f g"?

      Mark for Review
(1) Points
                         
               
f
    
               
e (*)
    
               
c
    
               
d
    
               
This code doesn't compile.
    
                         
                              Incorrect. Refer to Section 6 Lesson 1.
    
                         
          23.      What is the output of the following segment of code?

      Mark for Review
(1) Points
                         
               
321123
    
               
642
    
               
642246 (*)
    
               
312213
    
               
This code doesn't compile.
    
                         
                              Correct
    
                         
          24.      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
    
                         
          25.      What is wrong with this code?

      Mark for Review
(1) Points
                         
               
It is missing a semicolon.
    
               
It does not compile. (*)
    
               
It gives you an out of bounds exception.
    
               
There is nothing wrong with this code.
    
                         
                              Correct
  
Section 6
     (Answer all questions in this section)
                         
          26.      Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false?      Mark for Review
(1) Points
                         
               
True (*)
    
               
False
    
                         
                              Correct
    
                         
          27.      Of the options below, what is the fastest run-time?      Mark for Review
(1) Points
                         
               
n
    
               
n^2
    
               
lg(n) (*)
    
               
n*lg(n)
    
                         
                              Correct
    
                         
          28.      Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next smallest value and swapping it into the next index and so on until the array is sorted. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          29.      Why might a sequential search be inefficient?      Mark for Review
(1) Points
                         
               
It utilizes the "divide and conquer" method, which makes the algorithm more error prone.
    
               
It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*)
    
               
It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.
    
               
It is never inefficient.
    
                         
                              Correct
    
                         

                         
     Section 7
     (Answer all questions in this section)
                         
          30.      Which of the following is the correct way to code a method with a return type an object Automobile?      Mark for Review
(1) Points
                         
               
Automobile upgrade(String carA){
carA="Turbo";
return carA;}
    
               
Automobile upgrade(Automobile carA){
carA.setTurbo("yes");
return carA;} (*)
    
               
String upgrade(String carA){
carA="Turbo";
return carA;}
    
               
upgrade(Automobile carA) Automobile{
carA.setTurbo("yes");
return carA;}
    
               
None of the above. It is not possible to return an object.
    
                         
                              Correct
  
Section 7
     (Answer all questions in this section)
                         
          31.      Which of the following specifies accessibility to variables, methods, and classes?      Mark for Review
(1) Points
                         
               
Methods
    
               
Parameters
    
               
Overload constructors
    
               
Access modifiers (*)
    
                         
                              Incorrect. Refer to Section 7 Lesson 2.
    
                         
          32.      Which of the following are access modifiers?      Mark for Review
(1) Points
                         
               (Choose all correct answers)    
                         
               
protected (*)
    
               
public (*)
    
               
secured
    
               
default (no access modifier) (*)
    
               
private (*)
    
                         
                              Incorrect. Refer to Section 7 Lesson 2.
    
                         
          33.      Which of the following is the definition of a constructor?      Mark for Review
(1) Points
                         
               
A keyword that specifies accessibility of code.
    
               
A special method that is used to assign initial values to instance variables in a class. (*)
    
               
A way to call a method with a variable number of arguments using an elipse.
    
               
A variable in a method declaration that gets passed into the method.
    
                         
                              Correct
    
                         
          34.      Which segment of code correctly defines a method that contains two objects of class Tree as parameters?      Mark for Review
(1) Points
                         
               
void bloom(Tree pine, Tree oak) {//code here }; (*)
    
               
Tree bloom (pine, oak) {//code here };
    
               
void bloom, Tree pine, Tree oak {//code here };
    
               
None of the above, objects cannot be passed as parameters.
    
                         
                              Incorrect. Refer to Section 7 Lesson 2.
    
                         
          35.      What is Polymorphism?      Mark for Review
(1) Points
                         
               
A way of redefining methods with the same return type and parameters.
    
               
A way to create multiple methods with the same name but different parameters.
    
               
A class that cannot be initiated.
    
               
The concept that a variable or reference can hold multiple types of objects. (*)
    
                         
                              Correct
  
Section 7
     (Answer all questions in this section)
                         
          36.      Identify the correct way to declare an abstract class.      Mark for Review
(1) Points
                         
               
abstract public class ClassName{...}
    
               
public abstract ClassName(...)
    
               
public class abstract ClassName(...)
    
               
public abstract class ClassName{...} (*)
    
                         
                              Correct
    
                         
          37.      Abstract classes cannot implement interfaces. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          38.      A linear recursion requires the method to call which direction?      Mark for Review
(1) Points
                         
               
Forward
    
               
Backward (*)
    
               
Both forward and backward
    
               
None of the above
    
                         
                              Correct
    
                         
          39.      There is only one copy a static class variable in the JVM. True or false?      Mark for Review
(1) Points
                         
               
True (*)
    
               
False
    
                         
                              Correct
    
                         
          40.      Static methods can't change any class variable values at run-time. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
  
Section 7
     (Answer all questions in this section)
                         
          41.      In Java, an instance field referenced using the this keyword generates a compilation error. True or false?      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          42.      A constructor is used to create objects. True or false?      Mark for Review
(1) Points
                         
               
True (*)
    
               
False
    
                         
                              Correct
    
                         
          43.      A constructor must have the same name as the class where it is declared. True or false?      Mark for Review
(1) Points
                         
               
True (*)
    
               
False
    
                         
                              Correct
    
                         
          44.      Identify the driver class that correctly initializes employees Jane and Brandon. The Employee class is below.

public class Employee {
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n;
age = a;
salary = s;
}
//methods for this class would go here
}      Mark for Review
(1) Points
                         
               
public class driver_class {
public static void main(String[] args) {
Employee Jane = new Employee("Jane", 48, 35.00);
Employee Brandon = new Employee("Brandon", 36, 20.00);
}
} (*)
    
               
public class driver_class {
public static void main(String[] args) {
Employee("Jane", 48, 35.00);
Employee("Brandon", 36, 20.00);
}
}
    
               
public class driver_class {
public Employee{
Jane = new Employee("Jane", 48, 35.00);
Brandon = new Employee("Brandon", 36, 20.00);
}
}
    
               
public class Employee {
public class driver-class{
Employee Jane = new Employee();
Employee Brandon = new Employee();
}
}
    
                         
                              Incorrect. Refer to Section 7 Lesson 1.
    
                         
          45.      Which of the following creates a method that compiles with no errors in the class?      Mark for Review
(1) Points
                         
                  

    
                  

(*)
    
                  

    
               
All of the above.
    
               
None of the above.
    
                         
                              Incorrect. Refer to Section 7 Lesson 1.
  
Section 7
     (Answer all questions in this section)
                         
          46.      The following code creates an object of type Horse:
Whale a=new Whale();      Mark for Review
(1) Points
                         
               
True
    
               
False (*)
    
                         
                              Correct
    
                         
          47.      Which of the following is the correct way to call an overriden method needOil() of a super class Robot in a subclass SqueakyRobot?      Mark for Review
(1) Points
                         
               
Robot.needOil(SqueakyRobot);
    
               
SqueakyRobot.needOil();
    
               
super.needOil(); (*)
    
               
needOil(Robot);
    
                         
                              Correct
    
                         
          48.      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. Refer to Section 7 Lesson 4.
    
                         
          49.      Which of the following show the correct UML representation of the super class Planet and its subclass Earth?      Mark for Review
(1) Points
                         
               


(*)
    
               


    
               


    
               
None of the above.
    
                         
                              Incorrect. Refer to Section 7 Lesson 4.
    
                         
          50.      What is encapsulation?      Mark for Review
(1) Points
                         
               
A keyword that allows or restricts access to data and methods.
    
               
A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.
    
               
A structure that categorizes and organizes relationships among ideas, concepts of things with the most general at the top and the most specific at the bottom.
    
               
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods. (*)
    
                         
                              Incorrect. Refer to Section 7 Lesson 4.
  

1.      Select the statement that declares a number of type double and initializes it to 6 times 10 to the 5th power.    
double number=6*10^5;
double number=6e5; (*)
double number=6(e5);
double number=6*10e5;
 2.      Which of the following expressions will evaluate to true when x and y are boolean variables with opposite values?
I. (x || y) && !(x && y)
II. (x && !y) || (!x && y)
III. (x || y) && (!x ||!y)    
I only
II only
I and III
 II and III
I, II, and III (*)
3.      The six relational operators in Java are:    
>,<,=,!,<=,>=
>,<,==,!=,<=,>= (*)
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
4.      Examine the following code: What is the value of variable x?    
2 (*)
2.5
6         
14
5.      What is the result when the following code segment is compiled and executed?
int x = 22, y = 10;
double p = Math.sqrt( ( x + y ) /2);
System.out.println(p);
Syntax error "sqrt(double) in java.lang.Math cannot be applied to int"
4.0 is displayed (*)
2.2 is displayed
5.656854249492381 is displayed
ClassCastException
6.      Which of the following is not a legal name for a variable?
2bad (*)
zero
theLastValueButONe
year2000
7.      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);
6
0
-42
2 (*)
8.      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?
True
False (*)
9.      Which of the two diagrams below illustrate the correct syntax for variables used in an if-else statement?
Example A (*)
Example B
10.      In an if-else construct the condition to be evaluated must end with a semi-colon. True or false?
True
False (*)
Incorrect. Refer to Section 4 Lesson 2.
11.      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); }
}
}    
True
False (*)
12.      In Eclipse, when you run a Java Application, where may the results display?
Editor Window
Console View (*)
Debug View
Task List
None of the above
13.      A combination of views and editors are referred to as _______________.
A workspace
A physical location
A perspective (*)
All of the above
14.      You can return to the Eclipse Welcome Page by choosing Welcome from what menu?
File
Edit
Help (*)
Close
15.      A workspace is:    
The physical location onto which you will store and save your files.
The location where all projects are developed and modified.
The location where you can have one or more stored perspectives.
All of the above. (*)

16.      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;
}
continue; (*)
break;
return;
k+=1;
17.      One advantage to using a WHILE loop over a FOR loop is that a WHILE loop always has a counter. True or false?    
True
False (*)
18.      Consider that a Scanner has been initialized such that:
Scanner in = new Scanner(System.in);
Which of the following lines of code reads in the user's input and sets it equal to a new String called input?
String input = in.next(); (*)
String input = in.close();
String input = new String in.next();
String input = in.nextInt();
19.      Switch statements work on all input types including, but not limited to, int, char, and String. True or false?
True
False (*)
20.      What is wrong with the following class declaration?
class Account{ ;
privateint number;
privateString name;;
Account;;
}
Classes cannot include strings.
Classes cannot include mixed data types.
The constructor method has no definition. (*)
There is nothing wrong.
21.      A class always has a constructor. True or false?    
True (*)
False
22.      Which of the following creates an instance of the class below?
ThisClass t=new ThisClass();
ThisClass t;
ThisClass t=new ThisClass(3,4);
ThisClass t=new ThisClass(5); (*)
Incorrect. Refer to Section 5 Lesson 2.
23.      Which of the following creates a class named Student with one constructor, and 2 instance variables name and gpa?
public class Student { private String name; private float gpa; }
public class Student private String name; private float gpa; Student();
public class Student { private String name; private float gpa; Student(){ name="Jane Doe"; gpa=3.0;} } (*)
public class Student { private String name; Student{ name="Jane Doe"; float gpa=3.0; }
Incorrect. Refer to Section 5 Lesson 2.
24.      Which of the following creates an object from the Animal class listed below:
Animal cat=new Animal();
Animal cat=Animal(50,30);
Animal cat=new Animal(50,30); (*)
Animal cat=new Animal(50);
25.      What is true about the code below:
Car car1=new Car();
Car car2=new Car();
car2=car1;
The references car1 and car2 are pointing to two Car Objects in memory.
The reference car2 points to an exact copy of the Car Object that car1 references.
There are no more Car objects in memory.
There is a Car object that car1 referenced that is now slated for removal by the garbage collector. (*)
There is a Car object that car2 referenced that is now slated for removal by the garbage collector.
Incorrect. Refer to Section 5 Lesson 2.
26.      A constructor must have the same name as the class it is declared within. True or false?    
True (*)
False
     Section 6
27.      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]);    
444444 (*)
123321
246642
222222
This code doesn't compile.
28.      Which of the following statements adds 5 to every element of the one dimensional array prices and then prints it to the screen?    
for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+5);
System.out.println(prices[i]+5);
for(int i=1;i<prices.length;i++)
System.out.println(prices[i]+5);
for(int i=0;i<prices.length;i++)
System.out.println(prices[1]+5); (*)
Incorrect. Refer to Section 6 Lesson 1.
29.      Which of the following declares and initializes a two dimensional array that can hold 6 Object reference types?    
String[] array=new String[6];
Object array=new Object[6];
Object[][] array=new Object[2][3]; (*)
String[][] array=String[6];
30.      Which of the following declares and initializes a one dimensional array that can hold 5 Object reference types?    
String[] array=new String[5];
Object array=new Object[5]; (*)
Object[] array=new Object[4];
String[] array=String[4];
Incorrect. Refer to Section 6 Lesson 1.
31.      Which of the following creates a String reference named s and instantiates it?    
String s=""; (*)
s="s";
String s;
String s=new String("s"); (*)
32.      What will the following code segment output?
String s="\\\n\"\n\\\n\"";
System.out.println(s);    
\" \"

""\
""
\
""
              
\
"
\
" (*)
    
 "
\
"
\
"
"
                        
 Incorrect. Refer to Section 6 Lesson 2.
33.      The == operator can be used to compare two String objects. The result is always true if the two strings are have the exact same characters in each position of the String. True or false?    
True
False (*)
34.      Given the code
String s1 = "abcdef";
String s2 = "abcdef";
String s3 = new String(s1);
Which of the following would equate to false?    
s1 == s2
s1 = s2
s3 == s1 (*)
s1.equals(s2)
s3.equals(s1)
 35.      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?    
True
False (*)
36.      Which of the following correctly matches the symbol with its function?    
== (two equal signs) compares values of primitive types such as int or char. (*)
== (two equal signs) compares the values 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.
.equals() compares the value of non-primitive objects. (*)
37.      If an exception is thrown by a method, where can the catch for the exception be?    
There does not need to be a catch in this situation.
The catch must be in the method that threw the exception.
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 immediately after the throw.
38.      What does it mean to catch an exception?    
It means you have fixed the error.
It means to throw it.
It means to handle it. (*)
It means there was never an exception in your code.
     Section 7
 39.      Forward thinking helps when creating linear recursive methods. True or false?    
True
False (*)
Incorrect. Refer to Section 7 Lesson 2.
40.      Which case handles the last recursive call?    
The base case (*)
The primary case
The secondary case
The convergence case
The recursive case
Incorrect. Refer to Section 7 Lesson 2.
41.      Static methods can't change any class variable values at run-time. True or false?    
True  False (*)
Incorrect. Refer to Section 7 Lesson 2.
42.      It is possible to return an object in a method. True or false?
True (*)       False
43.      Which segment of code represents a correct way to define a variable argument method?    
String easyArray(String... elems) {//code} (*)
String easyArray(...String elems) {//code}
String... easyArray(String elems) {//code}
Integer easyArray... (int elems) {//code}
44.      Choose the correct implementation of a public access modifier for the method divide.    
divide(int a, int b, public) {return a/b;}
public divide(int a, int b) {return a/b;} (*)
divide(int a, int b) {public return a/b;}
divide(public int a, public int b) {return a/b;}
45.      What is true about the Object class?    
It is the highest superclass. (*)
It extends other classes.
Its methods can be overridden in subclasses. (*)
Its methods can be overloaded in subclasses. (*)
46.      Would this code be correct if a Dog is a HousePet? Why or Why not?
HousePet Scooby = new Dog();    
Yes, because it is an abstract class.
Yes, because polymorphism allows this since Dog is a subclass of HousePet. (*)
No, because ref must be declared either a HousePet or a Dog, but not both.
Maybe. There is no way to tell without seeing the methods for Dog and the methods for HousePet.
47.      If it is possible to inherit from an abstract class, what must you do to prevent a compiler error from occurring?    
It is not possible to inherit from an abstract class.
Create all new methods and variables different from the parent class.
Override all abstract methods from the parent class. (*)
Declare the child class as abstract. (*)
48.      Which of the following correctly describes an Is-A relationship?    
A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)
A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.
It restricts access to a specified segment of code.
A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.
49.      An access modifier is a keyword that allows subclasses to access methods, data, and constructors from their parent class. True or false?    
True (*)
False
50.      Which of the following demonstrates the correct way to create an applet Battlefield?    
public class Battlefield extends Applet{...} (*)
public Applet Battlefield{...}
public class Applet extends Battlefield{...}
public class Battlefield(Applet){...}

Section 4
 (Answer all questions in this section)
   1.  The six relational operators in Java are:   Mark for Review
(1) Points
      >,<,=,!,<=,>=
      >,<,==,!=,<=,>= (*)
      >,<,=,!=,<=,>=
      >,<,=,!=,=<,=>  
      Correct     
  2.  The three logic operators in Java are:   Mark for Review
(1) Points
    &&, ||, ! (*)
    !=,=,==
    &&,!=,=
    &,|,=
      Correct
  3.  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. Refer to Section 4 Lesson 3.
 
       4.  Which line of Java code will assign the square root of 11 to a?   Mark for Review
(1) Points
       double a=11^(1/2);
      double a=sqrt(11);
      int a=Math.sqrt(11);
      double a=Math.sqrt*11;
      double a=Math.sqrt(11); (*) 
      Correct
  5.  What two values can a boolean variable have?   Mark for Review  (1) Points
    Numbers and characters
    True and false (*)
    Relational and logic operators
    Arithmetic and logic operators
    Integers and floating point types
      Correct
   Page 1 of 10 Next  Summary
Test: Java Fundamentals Final Exam
      Section 4
 (Answer all questions in this section)
  6.  Given the following declaration, which line of Java code properly casts one type into another without data loss?
int i=3,j=4; double y=2.54;   Mark for Review  (1) Points
    int x=(double)2.54;
    double x=i/j;
    double x=(double)(i/j);
    double x= double i/j;
    double x=(double)i/j; (*)
      Correct
  7.  Which of the following is a legal identifier?   Mark for Review
(1) Points
    7up
      boolean
    grand Total
      apple (*)
    Correct
8.  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
      Incorrect. Refer to Section 4 Lesson 2.
  9.  When the For loop condition statement is met the construct is exited. True or false?   Mark for Review (1) Points
    True
    False (*)
      Incorrect. Refer to Section 4 Lesson 2.

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


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

Previous  Page 2 of 10 Next  Summary
Test: Java Fundamentals Final Exam
      Section 4
 (Answer all questions in this section)
  11.  A counter used in a For loop cannot be initialized within the For loop header. True or false?   Mark for Review  (1) Points
    True
    False (*)
      Correct
  12.  When you open more than one file in Eclipse the system will __________________.   Mark for Review  (1) Points
    Close the previously opened file.
    Use tabs to display all files open. (*)
    Put the new file opened in a View area only.
    None of the above.
      Incorrect. Refer to Section 4 Lesson 1.
  13.  A combination of views and editors are referred to as _______________.   Mark for Review
(1) Points
    A workspace
    A physical location
    A perspective (*)
    All of the above
      Incorrect. Refer to Section 4 Lesson 1.
  14.  In Eclipse, when you run a Java Application, where may the results display?   Mark for Review
(1) Points
    Editor Window
    Console View (*)
    Debug View
    Task List
    None of the above
      Correct
  15.  What are the Eclipse Editor Area and Views used for?   Mark for Review (1) Points
   (Choose all correct answers)
     To modify elements. (*)
     To navigate a hierarchy of information. (*)
     To choose the file system location to delete a file.
      Correct
Previous  Page 3 of 10 Next  Summary
Test: Java Fundamentals Final Exam
 Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 5
  16.  Which of the following best describes a WHILE loop?   Mark for Review (1) Points
    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.
    A loop that is executed repeatedly until the conditional statement is false. (*)
    A loop that contains a counter in parenthesis with the conditional statement.
      Correct
  17.  Switch statements work on all input types including, but not limited to, int, char, and String. True or false?   Mark for Review (1) Points
    True
    False (*)
      Correct
  18.  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. (*)
      Correct
 
    
  19.  Which of the following correctly matches the switch statement keyword to its function?   Mark for Review (1) Points
   (Choose all correct answers)
     switch: tells the compiler the value to compare the input against
     default: signals what code to execute if the input does not match any of the cases (*)
     case: signals what code is executed if the user input matches the specified element (*)
     if: records the user's input and sends it to the case statements to find a possible match
     switch: identifies what element will be compared to the element of the case statements to find a possible match (*)
      Correct
  20.  What is wrong with the following class declaration?
class Account{ ;
privateint number;
privateString name;;
Account;;
}
 Mark for Review (1) Points
          Classes cannot include strings.
      Classes cannot include mixed data types.
      The constructor method has no definition. (*)
      There is nothing wrong.
      Correct
Previous  Page 4 of 10 Next  Summary
Test: Java Fundamentals Final Exam

 

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

      Section 5
  21.  Which of the following may be part of a class definition?   Mark for Review (1) Points
     Instance variables
    Instance methods
    Constructors
    All of the above. (*)
    None of the above.
      Incorrect. Refer to Section 5 Lesson 2.
  22.  The constructor method must always have at least one parameter. True or false?   Mark for Review (1) Points
    True
    False (*)
      Correct
  23.  A constructor must have the same name as the class it is declared within. True or false?   Mark for Review (1) Points
    True (*)
    False
      Correct
  24.  The basic unit of encapsulation in Java is the primitive data type. True or false?   Mark for Review (1) Points
    True
    False (*)
      Correct
  25.  In Java, an instance field referenced using the this keyword generates a compilation error. True or false?   Mark for Review (1) Points
    True
    False (*)
      Correct

Previous  Page 5 of 10 Next  Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 5
  26.  A constructor is used to create objects. True or false?   Mark for Review (1) Points
    True (*)
    False
      Correct
Section 6
  27.  Which of the following statements adds all of the elements of the one dimensional array prices and then prints it to the screen?   Mark for Review (1) Points
  a)  for(int i=0;i<prices.length;i++)
System.out.println(prices[i]+1);
b)    System.out.println(prices);
c)    int total
for(int i=1;i total+=prices[i];
System.out.println(total); (*)
d)    int total=0;
for(int i=1;i total+=prices[i];
      Incorrect. Refer to Section 6 Lesson 1.
  28.  The following array declaration is valid. True or false?
int[] y = new int[5];   Mark for Review (1) Points
    True (*)
    False
      Correct
  29.  Which of the following statements is not a valid array declaration?   Mark for Review
(1) Points
    int number[];
    float []averages;
    double marks[5];
    counter int[]; (*)
      Incorrect. Refer to Section 6 Lesson 1.
  30.  What is the output of the following segment of code?
int num[]={9,8,7,6,5,4,3,2,1};
for(int i=0;i<9;i=i+3)
System.out.print(num[i]);   Mark for Review
(1) Points
    9630
    963 (*)
    987654321
    97531
    This code doesn't compile.
      Correct
Previous  Page 6 of 10 Next  Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 6
  31.  Consider the following code snippet.

What is printed?  Mark for Review (1) Points
    88888 (*)
    88888888
    1010778
    101077810109
    ArrayIndexOutofBoundsException is thrown
 
      Incorrect. Refer to Section 6 Lesson 2.
  32.  The following code is an example of instantiating a String object:
String str = String( "Hello" );
True or false?  Mark for Review (1) Points
    True
    False (*)
      Incorrect. Refer to Section 6 Lesson 2.
  33.  Suppose that str1 and str2 are two strings. Which of the statements or expressions are valid?  Mark for Review (1) Points
    String str3 = str1 - str2;
    str1 += str2; (*)
    str1 >= str2
    Str1 -= str2;
      Correct
  34.  The == operator tests if two String references are pointing to the same String object. True or false?   Mark for Review (1) Points
    True (*)
    False
      Correct
  35.  What does it mean to catch an exception?   Mark for Review (1) Points
    It means you have fixed the error.
    It means to throw it.
    It means to handle it. (*)
    It means there was never an exception in your code.
      Correct
Previous  Page 7 of 10 Next  Summary
Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 6
  36.  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. Refer to Section 6 Lesson 3.
  37.  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. (*)
     == (two equal signs) compares the values 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.
     .equals() compares the value of non-primitive objects. (*)
      Incorrect. Refer to Section 6 Lesson 3.
  38.  What is wrong with this code?

  Mark for Review (1) Points
    It is missing a semicolon.
    It does not handle the exception.
    It gives you an out of bounds exception.
    There is nothing wrong with this code. (*)
      Correct
Section 7
 (Answer all questions in this section)
  39.  Identify the correct way to declare an abstract class.   Mark for Review (1) Points
    abstract public class ClassName{...}
    public abstract ClassName(...)
    public class abstract ClassName(...)
    public abstract class ClassName{...} (*)
      Correct
  40.  Which of the following are true about abstract methods?   Mark for Review (1) Points
   (Choose all correct answers)
     They cannot have a method body. (*)
     They must be overridden in a non-abstract subclass. (*)
     They must be declared in an abstract class. (*)
     They may contain implementation.
     They must be overloaded.
      Correct
Previous  Page 8 of 10 Next  Summary
Test: Java Fundamentals Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 7
 (Answer all questions in this section)
  41.  What is true about the Object class?   Mark for Review (1) Points
   (Choose all correct answers)
     It is the highest superclass. (*)
     It extends other classes.
     Its methods can be overridden in subclasses. (*)
     Its methods can be overloaded in subclasses. (*)
      Correct
  42.  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
  43.  Which of the following correctly describes an Is-A relationship?   Mark for Review
(1) Points
    A helpful term used to conceptualize the relationships among nodes or leaves in an inheritance hierarchy. (*)
    A programming philosophy that promotes simpler, more efficient coding by using exiting code for new applications.
    It restricts access to a specified segment of code.
    A programming philosophy that promotes protecting data and hiding implementation in order to preserve the integrity of data and methods.
      Correct
  44.  If a variable in a superclass is private, could it be directly accessed or modified by a subclass? Why or why not?   Mark for Review (1) Points
          Yes. A subclass inherits full access to all contents of its super class.
    Yes. Any variable passed through inheritance can be changed, but private methods cannot.
    No. A private variable can only be modified by the same class with which it is declared regardless of its inheritance. (*)
    No. Nothing inherited by the super class can be changed in the subclass.
      Correct
  45.  Which of the following are access specifiers?   Mark for Review (1) Points
   (Choose all correct answers)
     protected (*)
     public (*)
     secured
     default (no access modifier) (*)
     private (*)
      Correct
Previous  Page 9 of 10 Next  Summary
Test: Java Fundamentals Final Exam
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
      Section 7
 (Answer all questions in this section)
  46.  Which of the following correctly defines overloading?   Mark for Review (1) Points
    Having more than one constructor with the same name but different arguments. (*)
    Having more than one constructor with different names and the same arguments.
    A variable argument method that returns an array.
    A type of access specifier that only allows access from inside the same class.
      Correct
  47.  Which of the following is the correct way to code a method with a return type an object Automobile?  Mark for Review (1) Points
 a)   Automobile upgrade(String carA){
carA="Turbo";
return carA;}
b)    Automobile upgrade(Automobile carA){
carA.setTurbo("yes");
return carA;} (*)
  c)    String upgrade(String carA){
carA="Turbo";
return carA;}
  d)    upgrade(Automobile carA) Automobile{
carA.setTurbo("yes");
return carA;}
    None of the above. It is not possible to return an object.
      Correct
 
  48.  Static methods can't act like "setter" methods. True or false?   Mark for Review
(1) Points
    True
    False (*)
      Incorrect. Refer to Section 7 Lesson 2.
  49.  Static classes are designed as thread safe class instances. True or false?   Mark for Review
(1) Points
    True
    False (*)
      Correct
  50.  Static methods can read instance variables. True or false?   Mark for Review (1) Points
    True
    False (*)
      Correct

Previous  Page 10 of 10 Summary
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
 Section 4  (Answer all questions in this section)

Artikel Terkait

Life with colorful experience

11 komentar


EmoticonEmoticon