Вы находитесь на странице: 1из 18

Review your answers, feedback, and question scores below.

An asterisk (*) indicates a correct


answer.
Section 4
(Answer all questions in this section)
1The 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
2The following program prints "Not Equal":
.

Mark for
Review
(1) Points

True or false?
True (*)
False
Correct
3Consider the following code snippet.
.

Mark for
Review
(1) Points

What is printed?

Cayrbniz
CayrbnizCayrbniz
yr (*)
ay
ArrayIndexOutofBoundsException is thrown
Correct
4What will the following code segment output?
.
String s="\\\n\"\n\\\n\"";
System.out.println(s);

Mark for
Review
(1) Points

\" \"
""\
""
\
""
\
"
\
" (*)
"
\
"
\
"
"
Correct
5Given 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)

Mark for
Review
(1) Points

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)
21Which 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

22What 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.
23What is the output of the following segment of code?
.

Mark for
Review
(1) Points

321123
642
642246 (*)
312213
This code doesn't compile.
Correct
24The following segment of code initializes a 2 dimensional array of
. primitive data types. True or false?
double[][] a=new double[4][5];
True (*)
False
Correct

Mark for
Review
(1) Points

25What 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

Mark for

swapping it into the next index and so on until the array is sorted.
True or false?

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)

4In Java, an instance field referenced using the this keyword generates a
1.compilation error. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct
4A constructor is used to create objects. True or false?
2.

Mark for
Review
(1) Points

True (*)
False
Correct
4A constructor must have the same name as the class where it is declared.
3.True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
4Identify the driver class that correctly initializes employees Jane and
4.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.
4Which of the following creates a method that compiles with no errors in
5.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.

Вам также может понравиться