Limited access

Upgrade to access all content for this subject

Consider the following method.

/**
 * @param oldContacts – fully populated array of contact names
 * @param newContacts - new array initialized with default String values
 * @return total length of all contact names
 */
public static int copyContacts(String[] oldContacts, String[] newContacts)
{
    for(int i=0; i<oldContacts.length; i++)
    {
        newContacts[i] = oldContacts[i];
    }

    int totLen = 0;
    for (String contact : newContacts)
    {
        totLen +=contact.length();
    }
    return totLen;
}

What condition would cause this method throw a NullPointerException?

A

It will always throw a NullPointerException.

B

It will never throw a NullPointerException.

C

When oldContacts contains more elements than newContacts.

D

When newContacts contains more elements than oldContacts.

E

When both oldContacts and newContacts have a size of 0.

Select an assignment template