Problem

Consider the following classes declared in the same package:public abstract class Account...

Consider the following classes declared in the same package:

public abstract class Account {

private String name;

private String acctNum;

protected double balance;

String taxID;

public Account(String name, String num) {

this.name = name;

acctNum = num;

} // end constructor

} // end Account

public class SavingsAcct extends Account {

double interestRate;

public SavingsAcct(String name, String num) {

// See part a)

} // end constructor

public class CheckingAcct extends Account {

double checkFee;

private double overdraftLimit;

public CheckingAcct(String name, String num,double fee) {

// See part b)

> // end constructor }

// end CheckingAcct

public class Stock {

private String stockCode;int numShares;

} // end Stock

a. Write code for the constructor diat could be used to initialize a SavingsAcct object.

b. Write code for the constructor that could be used to initialize a CheckingAcct object.

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 witiiout problem.

c. CheckingAcct c = new CheckingAcct("Janet", "JP4561", 0.5);

c.taxID = "987-65-4320";

c.acctNum = "123456";

d. Account a =new SavingsAcct("Diane", "DG0621");

a.balance = 10.00;

e. Account s =new Stock();

s. numShares = 2500;

f. Account a =neitf Account ("Marlene", "MP0108");

a.balance = 2500;

g. CheckingAcct c =new CheckingAcct("Karen", "KM0312", 0.5);

Account a = c;

a.checkFee = 0.75;

h. SavingsAcct s =new Account(“Mike", "MH0621");

s.interestRate = 1.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