Identify and describe the type errors in the following code.
```
1 public class GenericStuff {
2 public static void main ( String args[] ) {
3 Pair
4 new Player( "Rohal" ) );
5 Pair
6 Rental r1 = Rental(), rental2 = new Rental();
7
8 pPair.swapElements();
9 System.out.println( "Rental elements are " +
10 rentalPair
11 rentalPair.swapElements( rental1, rental2 );
12 Object o = rentalPair.getFirstElement();
13 }
14 }
```
line 5: rentalPair is declared as type 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();
You might also like to view...
If an IndexOfAny method is passed a string it:
a) finds the first occurrence of each letter in the string b) searches for the first occurrence of any of the characters in the string c) will search for the first occurrence of the sequence of characters d) generates an error
The enumeration FileAccess is used to ________.
a) control future users’ access to a file b) control program access to a file c) control the amount of updating that can be done on a file at once d) FileAccess is a method, not an enumeration.
What is the basic unit of information in an LDAP directory? What is the structure of an attribute?
What will be an ideal response?
An argument type followed by a(n) in a method’s parameter list indicates that the method receives a variable number of arguments of that particular type.
a. square brackets ([]) b. ellipsis (...) c. varargs keyword d. All of the above are acceptable to indicate a variable number of arguments.