You are on page 1of 20

Section 4

(Answer all questions in this section)


1Which line of Java code properly calculates the area of a triangle using
.A=1/2(b)(h) where b and h are Java primitive integers?

Mark for
Review
(1) Points

double A=1/2*b*h;
double A=1/2bh;
double A=(double)1/(double)2*b*h; (*)
double A=(double)(1/2)*b*h;
Incorrect. Refer to Section 4 Lesson 3.
2Which of the following is the name of a Java primitive data type?
.

Mark for
Review
(1) Points

Object
Rectangle
double (*)
String
Correct
3The following defines an import keyword:
.

Mark for
Review
(1) Points

Defines where this class lives relative to other classes, and provides
a level of access control.
Provides the compiler information that identifies outside classes
used within the current class. (*)
Precedes the name of the class.
Incorrect. Refer to Section 4 Lesson 2.
4The following defines a class keyword:
.

Mark for
Review
(1) Points

Defines where this class lives relative to other classes, and provides
a level of access control.
Provides the compiler information that identifies outside classes
used within the current class.

Precedes the name of the class. (*)


Incorrect. Refer to Section 4 Lesson 2.
5Consider the following code snippet.
.

Mark for
Review
(1) Points

What is printed?
55555
87658
AtlanticPacificIndianArcticSouthern
Code does not compile
ArrayIndexOutofBoundsException is thrown (*)
Incorrect. Refer to Section 4 Lesson 4.

Section 4
(Answer all questions in this section)
6.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?

Mark for
Review
(1) Points

True
False (*)
Correct
7.What is printed by the following code segment?

Mark for
Review
(1) Points

alligator (*)
albatross alligator
albatross
a1
Correct
8.Which of the following instantiates a String named name to Oracle?

Mark for
Review
(1) Points

String name;
String Oracle="name";
String name="name";
String name="Oracle"; (*)
Incorrect. Refer to Section 4 Lesson 4.
9.The == operator tests if two String references are pointing to the same
String object. True or false?

Mark for
Review
(1) Points

True (*)

False
Incorrect. Refer to Section 4 Lesson 4.
1In Eclipse, when you run a Java Application, the results are displayed in
0.a new window. True or False?

Mark for
Review
(1) Points

True
False (*)
Correct

Section 4
(Answer all questions in this section)
1A perspective is described as:
1.

Mark for
Review
(1) Points

A combination of views and editors (*)


A combination of views and windows
A combination of editor tabs
None of the above
Correct
1For every opening curly brace { there does not need to be a closing curly
2.brace} for the program to compile without error. True or False?

Mark for
Review
(1) Points

True
False (*)
Correct
1In the image below, identify the components.
3.

Mark for
Review
(1) Points

A-Main Method, B-Class, C-Package


A-Class, B-MainMethod, C-Package

A-Package, B-Main Method, C-Class (*)


None of the above
Correct
1A _______________ is used to organize Java related files.
4.

Mark for
Review
(1) Points

Project
Workspace
Package (*)
Collection
Incorrect. Refer to Section 4 Lesson 1.

Section 5
(Answer all questions in this section)
1In an if-else construct the condition to be evaluated must end with a
5.semi-colon. True or false?

Mark for
Review
(1) Points

True
False (*)
Correct

Section 5
(Answer all questions in this section)
16.This keyword is used to instruct specific code when the input for
a switch statement that does not match any of the cases.

Mark for Review


(1) Points

Switch
Case
Break
Default (*)
None of the above
Incorrect. Refer to Section 5 Lesson 1.
17.Which of the following correctly matches the switch statement
keyword to its function?

Mark for Review


(1) Points

(Choose all correct answers)


switch: tells the compiler the value to compare the input
against
default: signals what code to execute if the input does not
match any of the cases (*)
case: signals what code is executed if the user input matches
the specified element (*)
if: records the user's input and sends it to the case statements
to find a possible match
switch: identifies what element will be compared to the
element of the case statements to find a possible match (*)
Incorrect. Refer to Section 5 Lesson 1.
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 is true about a do-while loop?

Mark for Review

(1) Points
It is a post-test loop.
It is a modified while loop that allows the program to run
through the loop once before testing the boolean condition.
It continues looping until the condition becomes false.
All of the above. (*)
Incorrect. Refer to Section 5 Lesson 2.
20.What should replace the comment "//your answer here" in the
code below if the code is meant to take no action when i % 2 is 0
(in other words when i is even)?
for(int i = 0; i < 10; i++){<br> if(i%2 == 0)
//your answer here
else
k+=3;
}
continue; (*)
break;
return;
k+=1;
Correct

Mark for Review


(1) Points

Section 6
(Answer all questions in this section)
2The following array declaration is valid. True or false?
1.
int k[] = new int[10];

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 6 Lesson 1.
2What is the output of the following segment of code?
2.

Mark for
Review
(1) Points

321111
11 (*)
111
1111
This code doesn't compile.
Incorrect. Refer to Section 6 Lesson 1.
2The following segment of code initializes a 2 dimensional array of
3.references. True or false?
String[][] array={{"a", "b", "C"},{"a", "b", "c"}};

Mark for
Review
(1) Points

True (*)
False
Correct
2What is the output of the following segment of code?
4.
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 (*)

Mark for
Review
(1) Points

123321
246642
222222
This code doesn't compile.
Correct
2Of the options below, what is the fastest run-time?
5.

Mark for
Review
(1) Points

n
n^2
lg(n) (*)
n*lg(n)
Correct

Section 6
(Answer all questions in this section)
26.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
27.Which searching algorithm involves using a low, middle, and
high index value to find the location of a value in a sorted set of
data (if it exists)?

Mark for Review


(1) Points

Sequential Search
Merge Sort
Selection Sort
Binary Search (*)
All of the above
Incorrect. Refer to Section 6 Lesson 2.
28.Big-O Notation is used in Computer Science to describe the
performance of Sorts and Searches on arrays. True or false?

Mark for Review


(1) Points

True (*)
False
Correct
29.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 (*)
Correct

Mark for Review


(1) Points

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)
3How is it possible for overloading to work?
1.

Mark for
Review
(1) Points

There is no such thing as overloading.


The code has to be declared as private.
The interpreter doesn't care what you name your constructors.
Java Virtual Machine searches until it finds a constructor name and
argument type match. (*)
Incorrect. Refer to Section 7 Lesson 2.
3It is possible to overload a method that is not a constructor. True or
2.False?

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 7 Lesson 2.
3Which of the following are access modifiers?
3.

Mark for
Review
(1) Points

(Choose all correct answers)


protected (*)
public (*)
secured
default (no access modifier) (*)
private (*)
Incorrect. Refer to Section 7 Lesson 2.
3Which of the following is the definition of a constructor?
4.

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
3Consider creating a class Square that extends the Rectangle class
5.provided below. Knowing that a square always has the same width and
length, which of the following best represents a constructor for the
Square class?

(*)
None of the above.
Incorrect. Refer to Section 7 Lesson 4.

Mark for
Review
(1) Points

Section 7
(Answer all questions in this section)
36.Where should the constructor for a superclass be called?

Mark for Review


(1) Points

Anywhere inside the subclass.


Inside the main method of the subclass.
The last line in the constructor of the subclass.
The first line of the constructor in the subclass. (*)
The super constructor does not need to be called inside the
subclass.
Incorrect. Refer to Section 7 Lesson 4.
37.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
38.Why are hierarchies useful for inheritance?

Mark for Review


(1) Points

They keep track of where you are in your program.


They restrict a superclass to only have one subclass.
They organize constructors and methods in a simplified
fashion.
They are used to organize the relationship between a
superclass and its subclasses. (*)
Correct
39.Abstract classes cannot implement interfaces. True or false?

Mark for Review


(1) Points

True
False (*)
Correct
40.If it is possible to inherit from an abstract class, what must you do
to prevent a compiler error from occurring?

Mark for Review


(1) Points

(Choose all correct answers)


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. (*)
Incorrect. Refer to Section 7 Lesson 5.

Section 7
(Answer all questions in this section)
4It is possible to inherit from an abstract class. True or false?
1.

Mark for
Review
(1) Points

True (*)
False
Incorrect. Refer to Section 7 Lesson 5.
4The basic unit of encapsulation in Java is the primitive data type. True
2.or false?

Mark for
Review
(1) Points

True
False (*)
Correct
4The constructor method must always have at least one parameter. True
3.or false?

Mark for
Review
(1) Points

True
False (*)
Correct
4Which of the following creates a method that returns a boolean value?
4.

Mark for
Review
(1) Points

(*)

None of the above.


Correct
4Consider:
5.
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.
Correct

Mark for
Review
(1) Points

Section 7
(Answer all questions in this section)
46.What is true about the code below:
Car car1=new Car();
Car car2=new Car();
car2=car1;

Mark for Review


(1) Points

(Choose all correct answers)


The references car1 and car2 are pointing to two Car Objects
in memory.
The reference car2 points to an exact copy of the Car Object
that car1 references. (*)
There are no more Car objects in memory.
There is a Car object that car1 referenced that is now slated
for removal by the garbage collector.
There is a Car object that car2 referenced that is now slated
for removal by the garbage collector. (*)
Incorrect. Refer to Section 7 Lesson 1.
47.What is wrong with the following class declaration?
class Account{ ;
private int number;
private String name;;
public Account;
}

Mark for Review


(1) Points

Classes cannot include strings.


Classes cannot include mixed data types.
The constructor method has no definition. (*)
There is nothing wrong.
Correct
48.Static methods can write to instance variables. True or false?

Mark for Review


(1) Points

True
False (*)
Correct

49.Static methods can return any object type. True or false?

Mark for Review


(1) Points

True (*)
False
Incorrect. Refer to Section 7 Lesson 3.
50.Static classes are designed as thread safe class instances. True or
false?

Mark for Review


(1) Points

True
False (*)
Correct

You might also like