ReviewPart3

advertisement
Lewis/Loftus Java Software Solutions, 4e
TestBank- Chapter 9
For questions 1-4, assume values is an int array that is currently filled to capacity, with the following
values:
9
4
12
2
1)
What is returned by values[3]?
a) 9
b) 12
c) 2
d) 6
e) 3
2)
What is the value of values.length?
a) 0
b) 5
c) 6
d) 7
e) 18
6
8
18
3) What does the following code do? Assume list is an array of int values, temp is some previously
initialized int value, and c is an int initialized to 0.
for (j=0; j < list.length; j++)
if (list[j] < temp) c++;
a) It finds the smallest value and stores it in temp
b) It finds the largest value and stores it in temp
c) It counts the number of elements equal to the smallest value in list
d) It counts the number of elements in list that are less than temp
e) It sorts the values in list to be in ascending order
An int array stores the following values. Use the array to answer questions 4 – 7
9
4
12
2
6
8
18
4) Which of the following lists of numbers would accurately show the array after the first pass through
the Selection Sort algorithm?
a) 9, 4, 12, 2, 6, 8, 18
b) 4, 9, 12, 2, 6, 8, 18
c) 2, 4, 12, 9, 6, 8, 18
d) 2, 4, 6, 8, 9, 12, 18
e) 2, 4, 9, 12, 6, 8, 18
5) Which of the following lists of numbers would accurately show the array after the second pass of the
Selection Sort algorithm?
a) 9, 4, 12, 2, 6, 8, 18
b) 2, 4, 9, 6, 12, 8, 18
c) 2, 4, 12, 9, 6, 8, 18
d) 2, 4, 6, 8, 9, 12, 18
e) 2, 4, 12, 6, 8, 9, 18
1
Error! Bookmark not defined. © 2005
Lewis/Loftus Java Software Solutions, 4e
TestBank- Chapter 9
6) How many passes will it take in all for Selection Sort to sort this array?
a) 2
b) 4
c) 5
d) 6
e) 7
16) What are the main programming mechanisms that constitute object-oriented programming?
a) Encapsulation, inheritance, polymorphism
b) Encapsulation, abstraction, inheritance
c) Inheritance, polymorphism, recursion
d) Polymorphism, recursion, abstraction
e) None of the above
17) What is printed by the following code? Consider the polymorphic invocation.
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure");
}
}
class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle");
}
}
class Box extends Figure
{
void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
f = r;
2
Error! Bookmark not defined. © 2005
Lewis/Loftus Java Software Solutions, 4e
TestBank- Chapter 9
f.display( );
f = b;
f.display( );
}
public static void main(String[ ] args)
{
new Inherit( );
}
}
a)
Figure
Rectangle
Box
b) Rectangle
Box
c)
Figure
Figure
Figure
d) Syntax error. This code won't compile or execute
e)
None of the above
18) Polymorphism is achieved by
a) extending
b) overriding
c) embedding
d) abstraction
e) encapsulation
19) Which of the following statements is completely true?
a) If a class is declared to be abstract then every method in the class is abstract and must be
overridden
b) If a class is declared to be abstract then some methods in the class may have their bodies
omitted
c) If a class is declared to be abstract then all methods in the class must have their bodies
omitted
d) If a class is declared to be abstract then all the instance variables must be overridden
when a concrete class is derived from the abstract base class
3
Error! Bookmark not defined. © 2005
Lewis/Loftus Java Software Solutions, 4e
TestBank- Chapter 9
20) Which of these methods will sort an array of floats into ascending order?
a)
void arrange(float[ ] ary)
{
for (int n=0; n<ary.length; n++)
for (int k=n; k<ary.length; k++)
if (ary[n] > ary[k])
{
float x = ary[n];
ary[n] = ary[k];
ary[k] = x;
}
}
b)
void arrange(float[ ] ary)
{
for (int n=0; n<ary.length; n++)
for (int k=n; k<ary.length; k++)
if (ary[n] < ary[k])
{
float x = ary[n];
ary[n] = ary[k];
ary[k] = x;
}
}
c)
void arrange(float[ ] ary)
{
for (int n=1; n<=ary.length; n++)
for (int k=n; k<ary.length; k++)
if (ary[n] > ary[k])
{
float x = ary[n];
ary[n] = ary[k];
ary[k] = x;
}
}
d)
void arrange(float[ ] ary)
{
for (int n=0; n<ary.length; n++)
for (int k=n; k<ary.length; k++)
if (ary[n] > ary[k])
float x = ary[n];
ary[n] = ary[k];
ary[k] = x;
}
e)
None of the above
4
Error! Bookmark not defined. © 2005
Download