Problem

Assume the following classes added to the same package as the classes presented in Exercis...

Assume the following classes added to the same package as the classes presented in Exercise 14.

import java.util.*;

public class Portfolio{

private ArrayList accounts = new 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. PortfoliomyAccts = new Portfolio();

myAccts.addAcct(new CheckingAcct(“Kate”, “KR1225”, 0.5));

b. PortfoliomyAccts = new Portfolio();

myAccts.addAcct(new SavingsAcct(“Andrew”, “AH0527“));

c. PortfoliomyAccts = new Portfolio();

myAccts.addAcct(new Stock());

d. Portfolio? extends Account>accl;

Portfolioacc2 = new Portfolio();

accl = acc2;

e. Portfolio myAccts = new Portfolio();

myAccts.addAcct(new CheckingAcct(“Sarah”, “SH0604”,0.5));

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT