Question: QUESTION 5 Consider the following code snippet: public class Box { private E data; public Box() { . . . } public void insert(E value)
QUESTION 5
Consider the following code snippet:
public class Box
{ private E data;
public Box() { . . . } public void insert(E value) { . . . } }
What will result from executing the following code?
Boxbox = new Box ();
box.insert("blue Box"); | A. | compile-time error | |
| B. | run-time error | |
| C. | correct generic assignment | |
| D. compile-time warning |
QUESTION 6
Consider the following code snippet:
public class Box
{ private E data;
public Box() { . . . } public void insert(E value) { . . . } public E getData() { . . . } }
What will result from executing the following code?
Boxbox = new Box ();
Box b = (Box) box.getData();
| A. | compile-time error | |
| B. | run-time error | |
| C. | correct generic assignment | |
| D. | compile-time warning |
QUESTION 7
Consider the following code snippet:
public class Box
{ private E data;
public Box(){ . . . } public void insert(E value) { . . . } public E getData() { . . . } }
What will result from executing the following code?
Boxbox = new Box ();
. . .
box.insert("blue Box"); String b = (String) box.getData();
| A. | compiler error | |
| B. | run-time error | |
| C. | correct, but unnecessary cast | |
| D. | correct, with necessary cast |
QUESTION 12
Consider the following code snippet:
ArrayListcoins1 = new ArrayList (); //Line 1
LinkedList coins2 = new LinkedList(); //Line 2
coins1.add("my penny"); //Line 3 coins2.addFirst("my penny"); //Line 4 Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?
| A. | Line 1 | |
| B. | Line 2 | |
| C. | Line 3 | |
| D. | Line 4 |
QUESTION 13
Consider the following code snippet:
ArrayListaccounts1 = new ArrayList (); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
accounts1.add("my Salary"); //Line 3 accounts2.addFirst("my Salary"); //Line 4 Which of the above lines will cause a compile-time error?
| A. Line 1 | ||
| B. | Line 2 | |
| C. | Line 3 | |
| D. | Line 4 |
QUESTION 14
Consider the following code snippet:
ArrayListaccounts1 = new ArrayList (); //Line 1
LinkedList accounts2 = new LinkedList(); //Line 2
accounts1.add("my Salary"); //Line 3 accounts2.addFirst("my Salary"); //Line 4 Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?
| A.Line 1 | ||
| B. | Line 2 | |
| C. | Line 3 | |
| D. | Line 4 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
