public class IntPair
{
private int firstValue;
private int secondValue;
public IntPair(int first, int second)
{
firstValue = first;
secondValue = second;
}
public int getFirst()
{ return firstValue; }
public int getSecond()
{ return secondValue; }
public void setFirst(int a)
{ firstValue = a; }
public void setSecond(int b)
{ secondValue = b; }
}
Consider the following program that uses the IntPair class:
public class TestSwap
{
public static void swap(IntPair pair)
{
int temp = pair.getFirst();
pair.setFirst(pair.getSecond());
pair.setSecond(temp);
}
public static void Main(String[] args)
{
int x = 8, y = 6;
/* code to swap x and y */
}
}
Which is a correct replacement for /* code to swap x and y */?
I) IntPair iPair = new IntPair(x, y);
swap(x, y);
x = iPair.getFirst();
y = iPair.getSecond();
II) IntPair iPair = new IntPair(x, y);
swap(iPair);
x = iPair.getFirst();
y = iPair.getSecond();
III) IntPair iPair = new IntPair(x, y);
swap(iPair);
x = iPair.setFirst();
y = iPair.setSecond();
(A) I only
(B) II only
(C) III only
(D) II and III only
(E) None is correct.