CSCE 156 PreTest
January 11, 2007
This examination consists of 28 multiple-choice
questions and you have 30 minutes to complete the test.
Please read every question carefully. If you have questions, please raise your hand
and I will come to you.
1. What is the
relationship between a class and an object of that class?
- A class is a kind of mold
or template that dictates what objects can and cannot do.
- An
object is the same as a class.
- A
class is an instance of an object.
- A
class is like CSCE156 and an object is like a student registered in CSCE156.
2. Which of the
following is not a class-object pair?
- Robot
– R2D2
- Car –
Toyota
- Course
– CSCE156
- Parking Lot – Car-1
3. Which
statement is not true in the following?
- A
method is like what somebody can do, and a message is like what I, as a
programmer, can send to that somebody to ask that somebody to perform that
method.
- To
instruct a class or an object to perform a method, we send a message to
it.
- Messages are the input and
output of a method.
4. What is
object-oriented programming? (Choose the
best answer.)
- It’s
about solving problems modularly.
- It’s
about defining classes (molds!), instantiating objects from these classes,
and asking these objects to interact and do things for us.
- It’s about defining the
objectives of each component in the program, resolving conflicts among the
objectives, implementing them in classes, and instantiating objects from
these classes to solve problems.
5. What does a
class have?
I. Data values II. Methods
III. Objects IV. Arguments
- II
& III
- I,
II, & III
- I & II
- I,
II, III & IV
6. Which of the
following is not true about a class method and an instance method?
- A
class method is one that a programmer can use without having to
instantiate an object of that class
- An
instance method is one that a programmer can only use by asking an
instantiated object of that class to do
- A
method that deals with collective information about the instances of a
class is usually defined as class method.
- A
method that deals with a particular individual instance is called an
instance method.
- A, B, C, and D are false.
7. What is the
order of the Software Engineering phases?
- Design,
Analysis, Coding, Testing, Operation (Maintenance)
- Analysis, Design, Coding,
Testing, Operation (Maintenance)
- Coding,
Analysis, Design, Testing, Operation (Maintenance)
- Design,
Analysis, Coding, Operation (Maintenance), Testing
8. Which of the
following is not true about a “main” or “application” Java class?
- A
“main” class can be invoked/run as an application.
- A “main” class does not
have a class definition.
- A
“main” class has a “main” method.
- A
“main” class uses other basic classes
9. Assuming that the class Ewok has been
correctly implemented, will the following code compile?
class TestEwok {
public static void main (String[] args) {
Ewok myEwok1;
myEwok1.printInfo();
}
}
- Yes
- No
10. In Java, given
x = 10, y = 7, z = 2.5, what is the value of the following expression?
x+3 / y +z * x%2
- 10
- 11.4286
- 11
- 11.0
- 10.4286
11. Which of the
following statements are true?
I. Usually, a data member of a class is
declared “private.”
II. Usually, a method of a class is declared
“public.”
III. Methods that client programmers do not need to
know about or do not need to use should be declared “private.”
IV. Sometimes, data members such as constants are
declared “public” so that client programmers could access them (since constants
cannot be modified).
- I
& II only
- I,
II, & III only
- I, II, III, & IV
- I,
II, & IV only
12. What is the
output of running TestJedi?
class Jedi {
private String name;
private double level;
…
public Jedi() {
name = “pupil”;
level = 0;
}
public void setLevel(double x) {
int level;
level = x;
}
public double getLevel() {
return level;
}
}
class TestJedi {
public static void
main(String[] args) {
Jedi apprentice1 = new Jedi();
apprentice1.setLevel(0.5);
System.out.println(apprentice1.getLevel());
}
}
- 0.0
- 0.5
- undefined
13. What is
overloading a method?
- Invoking
a method with too many arguments
- Defining multiple methods
with the same method name but with different parameters (and
implementations)
- Defining
the Constructor method such that it invokes other methods
- Defining
the Constructor method such that it instantiates other classes
14. Which of the
following is not true about a local variable?
- A
variable declared within the method declaration is called a local
variable.
- Local
variables are used for temporary purposes, such as storing intermediate
results of a computation.
- Local variables can be
accessed from outside the method through an instance of the class to which
the method belongs.
- Local
variables are erased when the execution of a method is completed.
15. Given the if
statement shown, what is the output when x = 2, y = 5, and z = 3?
output = 0;
if ( x >= 3)
output = 5;
else if (y < 4
&& z < 3)
output = 6;
else if (z >= 3) {
output = 7;
if (y < 4)
output = 8;
}
- 0
- 5
- 6
- 7
- 8
16. Which of the
following is not true about pre-test and post-test loops?
- While
loops are pre-test loops
- For
loops are pre-test loops
- Do-while
loops are post-test loops
- A
post-test loop executes the body of the loop at least once
- A pre-test loop is exactly
the same as a post-test loop in terms of functionality and logic
17. Which of the
following is not true about count-controlled and sentinel-controlled
loops?
- For
loops are the natural implementation choice for count-controlled loops
- While
loops are the natural implementation choice for sentinel-controlled loops
- If
one knows exactly the number of iterations for a loop, then one should use
a count-controlled loop
- If
the number of iterations for a loop depends on certain condition or event
becoming true, then one should use a sentinel-controlled loop
- A loop cannot be both
count-controlled and sentinel-controlled
18. Given the
while statement shown, what is the equivalent for loop implementation?
int j = 0;
while ( j < 10) {
j = j
+ 2;
int
i = j;
while
(i < 20) {
i
= i + j;
}
}
A. for (int j
= 0; j < 10; j = j+2)
for
(int i = j; i < 20; i = i+j);
B. for (int j = 0; j = j+2;
j < 10)
for (int i = 0; i < 20; i =
i+j);
C.
for (int
j = 0; j < 10; j = j++) {
j = j + 2;
for (int i
= j; i < 20; i++) {
i = i + j;
}
}
19. Which of the
following is not pertinent to the delegation-based event model in Java?
- Event
sources
- Event
handlers
- Event
listeners
- Event performers
20. Which of the
following must be done to build an effective Java GUI?
I.
Declare and create event sources
II. Associate an event listener to
each event source
III. Handle each event that
requires response
IV. Implement ActionListener
- I and
II
- I, II, and III
- I,
II, and IV
- I,
II, III, and IV
21. Why do we
want to use exception handling in our programs?
(Choose the best answer)
- To
make the programs easier to debug
- To make the programs more
reliable/robust
- To
get the programs to compile
22. Which of the
following is not true?
- An exception
represents an error condition that can occur during the normal course of
program execution.
- When
an exception occurs, we say that an exception is thrown.
- When
the matching exception-handling code is executed, we say that the thrown
exception is caught.
- When an exception occurs,
the normal sequence of flow continues but the exception-handling routine
is also executed.
23. What is the
output of this try-catch block if inputStr is “1000”?
try {
num = Integer.parseInt(inputStr);
if (num > 100)
throw new Exception (“Too Large”);
}
catch (NumberFormatException e) {
System.out.println(“Cannot convert.”);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
finally {
System.out.println(“Done”);
I. “Too Large”
II.
“Cannot convert”
III. A Java-specific exception message
IV.
“Done”
- I
- I & IV
- II
& IV
- III
& IV
24. What are the
values of persons[0] and persons[1]?
int persons[10];
persons[0] = 1;
persons[1] = 2;
int temp = 3;
temp = persons[0];
persons[0] = persons[1];
persons[1] = temp;
- 1, 2
- 2, 3
- 1, 3
- 2, 1
- 3, 1
25. Which of the
following is not true about binary search?
- Its complexity is O(n)
- It
runs faster than a linear search
- The
list of elements involved has to be sorted first
- If
there are 8 elements (numbers) in the list, in the worst case scenario,
the search needs to look at only 3 elements to determine whether a
user-specified element is in the list
26. Which of the
following is not a benefit of using Inheritance?
- Better
organization of different but related classes
- More
efficient coding
- Easier
to maintain
- Can
make use of polymorphism
- Can increase the amount of
duplicated code
27. Which of the
following is not correct?
- Common
data members of subclasses should be declared as data members of the
superclass
- The subclasses of a
superclass should cover all possible instances of that superclass
- To
use polymorphism effectively, all subclasses and the superclass should
share the same “behavior” even though how the “behavior” is actually
carried out can be different
28. If s is “lincoln”, what is the
output of the mystery function?
function mystery(String s) {
if (s is an empty string)
print(“”)
else {
print(first char
of s)
print(last char of
s)
mystery(s without
1st and last chars)
}
}
// end function
- linccoln
- lnilnocc
- lliinnccoollnn
- lincolnnlocnil