Consider the following declaration public interface HasHeight { // returns the h
ID: 3643420 • Letter: C
Question
Consider the following declarationpublic interface HasHeight
{
// returns the height of an item
double height()
}
Assume the following data field and method are declared in another class.
private HasHeight[] list;
public HasHeight getIt(HasHeight hh)
{
HasHeight current;
int k = 0;
while(k < list.length && list[k].height() >= hh.height())
k++;
if(k == list.length)
return hh;
else
current = list[k];
while(k < list.length)
{
if(list[k].height() < hh.height() && list[k].height() > current.height())
current = list[k];
k++;
}
return current;
}
Assume that bobby is an instance of a class that implements HasHeight. Which of the following best describes the item returned by the call getIt(bobby)?
*ANSWER CHOICES*
A.) bobby is always returned.
B.) The tallest item in list among those that are taller than bobby is returned; if there is no such item, then bobby is returned.
C.) The shortest item in list among those that are taller than bobby is returned; if there is no such item, then bobby is returned.
D.) The tallest item in list among those that are shorter than bobby is returned; if there is no such item, then bobby is returned.
E.) The shortest item in list among those that are shorter than bobby is returned; if there is no such item, then bobby is returned.
Explanation / Answer
C.) The shortest item in list among those that are taller than bobby is returned; if there is no such item, then bobby is returned.