PhoneEntry[] phoneBook = new PhoneEntry[ 5 ] ;

A good answer might be:

phoneBook is an array of 5 references to phoneEntry objects. But so far there are no phoneEntry objects and every slot of phoneBook is null.

Skeleton Application

Yes, you already knew that. But it is easy to forget. Here is a skeleton of the application:

class PhoneEntry
{
  String name;    // name of a person
  String phone;   // their phone number

  PhoneEntry( String n, String p )
  {
    name = n; phone = p;
  }
}

class PhoneBook
{ 
  PhoneEntry[] phoneBook; 

  PhoneBook()    // constructor
  {
    phoneBook = new PhoneEntry[ 5 ] ;
 
    // load the phone book with data
    . . . .   
  }

  PhoneEntry search( String targetName )  
  {
    // use linear search to find the targetName
    . . . .
  }
}
class PhoneBookTester
{
  public static void main ( String[] args )
  {
    PhoneBook pb = new PhoneBook();  
  
    // search for "Violet Smith"
    PhoneEntry entry = 
        pb.search( "Violet Smith" ); 

    if ( entry != null )
      System.out.println( entry.name + 
          ": " + entry.phone );
    else
      System.out.println("Name not found" );

  }
}

The class PhoneBook contains the data and a search method. Its search method will return a reference to the PhoneEntry that matches the name being sought.

QUESTION 18:

What will the search method return if no matching PhoneEntry is found?

Click Here after you have answered the question