Limited access

Upgrade to access all content for this subject

Consider the following class.

public class Customer 
{
    private int custNum; 
    private int[] orders;    // list of customer order numbers

    // other instance variables, constructors and methods not shown
}

Note that orders will contain at least one customer order number and it will always be full of customer order numbers. Which of the following methods would return the last customer order number for this customer?

I.

    public int getLastCustOrderNum()
    {
        return orders[orders.length-1];
    }

II.

    public int getLastCustOrderNum() 
    {
        int i=0;
        for (i=0; i<orders.length; i++) ;
        {
            return orders[i-1];
        }
    }

III.

    public int getLastCustOrderNum()
    {
        int order=0;
        for (int i=0; i<orders.length; i++)
        {
            order = orders[i];
        }
        return order;
    }
A

I only.

B

III only.

C

I and II only.

D

I and III only.

E

I, II, and III.

Select an assignment template