Assume the following classes added to the same package as the classes presented in Exercise 14.
import java.util.*;
public class Portfolio
private ArrayList
private int numAccts = 0;
public void addAcct(T a) {
accounts.add(numAccts, a);
numAccts++;
} // end addAcct }
// end Portfolio
For the following code snippets, which are contained in the same package as the classes just given, identify whether the code
[A] fails to compile,
[B] compiles with a warning,
[C] generates an error at runtime,or
[D] compiles and runs without problem.
a. Portfolio
myAccts = new Portfolio (); myAccts.addAcct(new CheckingAcct(“Kate”, “KR1225”, 0.5));
b. Portfolio
myAccts = new Portfolio (); myAccts.addAcct(new SavingsAcct(“Andrew”, “AH0527“));
c. Portfolio
myAccts = new Portfolio (); myAccts.addAcct(new Stock());
d. Portfolio? extends Account>accl;
Portfolio
acc2 = new Portfolio (); accl = acc2;
e. Portfolio myAccts = new Portfolio();
myAccts.addAcct(new CheckingAcct(“Sarah”, “SH0604”,0.5));
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.