Identify and describe the type errors in the following code.

```
1 public class GenericStuff {
2 public static void main ( String args[] ) {
3 Pair pPair = new Pair( new Player( "Tom" ),
4 new Player( "Rohal" ) );
5 Pair rentalPair new Pair( new Rental(), new Item() );
6 Rental r1 = Rental(), rental2 = new Rental();
7
8 pPair.swapElements();
9 System.out.println( "Rental elements are " +
10 rentalPair.toString() );
11 rentalPair.swapElements( rental1, rental2 );
12 Object o = rentalPair.getFirstElement();
13 }
14 }

```

line 5: rentalPair is declared as type Pair but is instantiated as Pair.
line 5: depending on rentalPair’s type, one of the parameters to the constructor is incorrect
line 6: a new operator is required to initialize r1.
line 10: the type is not required. Correct statement: rentalPair.toString();
line 11: the header of swapElements does not require a parameter list.
Correct statement: rentalPair.swapElements();

Computer Science & Information Technology

You might also like to view...

You have six DHCP servers on your network, but only four of them are being displayed in the IPAM Server Inventory window. What action should you take that will most likely cause the other two servers to be displayed?

A. Configure the IPAM server as a DHCP server B. Make the other two servers domain members C. Demote the two missing servers D. Set the DHCP inventory limit to 10

Computer Science & Information Technology

Software-generated interrupts in the IA-32 architecture can be used to ________.

a) indicate errors occurring in hardware b) perform system calls c) indicate an I/O completion d) none of the above

Computer Science & Information Technology