You are on page 1of 15

Section 4

(Answer all questions in this section)


1.

What is printed by the following code segment?

Mark for Review


(1) Points
alligator
albatross alligator
albatross
a1
2.

The following code prints 5 "a"'s to the screen:

Mark for Review


(1) Points
True
False
3.

The following code is an example of creating a String re

ference:
String s;
True or false? Mark for Review
(1) Points
True
False
4.

What is printed?
(1) Points
88888

Consider the following code snippet.

Mark for Review

88888888
1010778
101077810109
ArrayIndexOutofBoundsException is thrown
5.
The String methods equals and compareTo perform similar
functions and differ in their return type. True or false?
Mark for Review
(1) Points
True
False
Section 4
(Answer all questions in this section)
6.
You can return to the Eclipse Welcome Page by choosing W
elcome from what menu? Mark for Review
(1) Points
File
Edit
Help
Close
7.
For every opening curly brace { there does not need to b
e a closing curly brace} for the program to compile without error. True or False
?
Mark for Review
(1) Points
True
False
8.
When converting gallons to liters its best to put the ca
lculation result into a variable with a _______________ data type.
Mark for
Review
(1) Points
int

double
boolean
None of the above
9.
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.
10.

A perspective is described as: 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
Section 4
(Answer all questions in this section)
11.
Which of the two diagrams below illustrate the general f
orm of a Java program?
Mark for Review
(1) Points
Example A
Example B
12.

The following defines a class keyword: Mark for Review

(1) Points
Defines where this class lives relative to other classes, and provides a
level of access control.
Provides the compiler information that identifies outside classes used w
ithin the current class.
Precedes the name of the class.
13.

Examine the following code:

What is the value of variable x?


(1) Points

Mark for Review

2
2.5
6
14
14.

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

Section 5
(Answer all questions in this section)
15.
Review
(1) Points

The six relational operators in Java are:

Mark for

>,<,=,!,<=,>=
>,<,==,!=,<=,>=
>,<,=,!=,<=,>=
>,<,=,!=,=<,=>
Section 5
(Answer all questions in this section)
16.

How would you use the ternary operator to rewrite this i

f statement?
if (balance < 500)<
fee = 10;
else
fee = 0;
Mark for Review
(1) Points
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;
17.

Consider that a Scanner has been initialized such that:

Scanner in = new Scanner(System.in);


Which of the following lines of code reads in the user's input and sets it equal
to a new String called input? Mark for Review
(1) Points
String input = in.next();
String input = in.close();
String input = new String in.next();
String input = in.nextInt();

18.
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?
Mark for Review
(1) Points
True
False
19.
In a for loop the counter is not automatically increment
ed after each loop iteration. Code must be written to increment the counter. Tru
e or false?
Mark for Review
(1) Points
True
False
20.
When the for loop condition statement is met the constru
ct is exited. True or false?
Mark for Review
(1) Points
True
False
21.
Why might a sequential search be inefficient?
(1) Points

Mark for Review

It utilizes the "divide and conquer" method, which makes the algorithm m
ore error prone.
It requires incrementing through the entire array in the worst case, whi
ch 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.
22.
A sequntial search is an iteration through the array tha
t stops at the index where the desired element is found. True or false?
Mark for Review
(1) Points

True
False
23.
Selection sort is efficient for large arrays. True or fa
lse?
Mark for Review
(1) Points
True
False
24.
Which of the following is the correct lexicographical or
der for the conents of the int array?
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22}
(1) Points

Mark for Review

{71, 1, 3, 28,29, 50, 22, 83, 1, 17}


{83, 71, 50, 29, 28, 22, 17, 3, 1, 1}
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
{1, 2, 7, 0, 9, 5, 6, 4, 8, 3}
{1, 1, 3, 17, 22, 28, 29, 50, 71, 83}
25.
If an exception has already been thrown, what will the i
nterpreter read next in the program?
Mark for Review
(1) Points
The next line of the program even if it is not the catch block of code.
Where the program catches the exception.
The end of the program.
The user input.
Section 6
(Answer all questions in this section)
26.

Which of the following statements add all of the element

s 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);
27.
Which of the following declares and initializes a one di
mensional array that can hold 5 Object reference types?
Mark for Review
(1) Points
String[] array=new String[5];
Object array=new Object[5];
Object[] array=new Object[4];
String[] array=String[4];
28.
The following segment of code initializes a 2 dimensiona
l array of primitive data types. True or false?
double[][] a=new double[4][5]; Mark for Review
(1) Points
True
False
29.

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.

Section 7
(Answer all questions in this section)
30.
All objects, in Java, are created using int. True or fal
se?
Mark for Review
(1) Points
True
False
Section 7
(Answer all questions in this section)
31.
The basic unit of encapsulation in Java is the primitive
data type. True or false?
Mark for Review
(1) Points
True
False

oolean value?
(1) Points

32.
Which of the following creates a method that returns a b
Mark for Review

None of the above.


33.

Which of the following creates an instance of the class

below?
Mark for Review
(1) Points
ThisClass t=new ThisClass();
ThisClass t;
ThisClass t=new ThisClass(3,4);
ThisClass t=new ThisClass(5);
34.

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 r
eferences.
There are no more Car objects in memory.
There is a Car object that car1 referenced that is now slated for remova
l by the garbage collector.
There is a Car object that car2 referenced that is now slated for remova
l by the garbage collector.
35.
The following code is a good example of using the this r
eference. True or false?

Mark for Review


(1) Points
True
False
Section 7
(Answer all questions in this section)
36.
If it is possible to inherit from an abstract class, wha
t 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.
37.

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 parame
ters.
A class that cannot be initiated.
The concept that a variable or reference can hold multiple types of obje
cts.
38.

What is true about the Object class?

(1) Points
(Choose all correct answers)
It is the highest superclass.
It extends other classes.

Mark for Review

Its methods can be overridden in subclasses.


Its methods can be overloaded in subclasses.
39.
Static methods can write to class variables. True or fal
se?
Mark for Review
(1) Points
True
False
40.
Static methods can't act like "setter" methods. True or
false? Mark for Review
(1) Points
True
False
Section 7
(Answer all questions in this section)
41.
Static classes can extend their parent class. True or fa
lse?
Mark for Review
(1) Points
True
False
42.
Which of the following could be a reason to return an ob
ject? 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 t
he updated object outside of the method.
None of the above. It is not possible to return an object.
43.

Which segment of code represents a correct way to define

a variable argument method?


(1) Points

Mark for Review

String easyArray(String ... elems) {//code}


String easyArray(... String elems) {//code}
String ... easyArray(String elems) {//code}
Integer easyArray ... (int elems) {//code}
44.

Which of the following are access modifiers?

Mark for

Review
(1) Points
(Choose all correct answers)
protected
public
secured
default (no access modifier)
private
45.
uctor. True or False?
(1) Points

It is possible to overload a method that is not a constr


Mark for Review

True
False
Section 7
(Answer all questions in this section)
46.
argument method?
(1) Points

Which of the following is the definition for a variable


Mark for Review

A way to create a new class.


Specifies accessibility to code.

Having more than one constructor with the same name but different argume
nts.
A type of argument that enables calling the same method with a different
number of arguments.
47.
If a variable in a superclass is private, could it be di
rectly 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.
48.

What is the Java Applet?

Mark for Review

(1) Points
(Choose all correct answers)
It is the virtual machine that translates Java code into a representatio
n that the computer can understand.
A web-based Java program that is embedded into a web browser.
A graphic visual included in Java.
There is no such thing as a Java Applet.
49.

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, co

ncepts of things with the most general at the top and the most specific at the b
ottom.
A programming philosophy that promotes protecting data and hiding implem
entation in order to preserve the integrity of data and methods.
50.
If you inherit a class, you do not inherit the class' co
nstructors. True or false?
Mark for Review
(1) Points
True
False

You might also like