Question

Consider the classes Sphere and Ball described in class and in Chapter 9 (beginning on page...

Consider the classes Sphere and Ball described in class and in Chapter 9 (beginning on page 457). Consider a variation on the classes where Ball overrides both the area() and displayStatistics() methods, and the displayStatistics() methods in each one calls area(). You have b1 and s1 as declared below:

Sphere s1 = new Sphere();

Ball b1 = new Ball();

For each scenario below, indicate if the assignments are legal or illegal. In addition for legal assignments also explain which version of area each all to displayStatistics() invokes.

  1. s1.displayStatistics();

b1.displayStatistics();

  1. s1.displayStatistics();

s1 = b1;

s1.displayStatistics();

b1.displayStatistics();

  1. s1.displayStatistics();

b1 = s1;

s1.displayStatistics();

b1.displayStatistics();

Homework Answers

Answer #1

In the above question, as Ball overrides both the area() and display statisticts() so the Ball class is the subclass and the Sphere class is the parent class.

1) s1.displayStatistics();

b1.displayStatistics();

This is an legal assignment.

The area() method that the above assignment will invoke.

s1.displayStatistics(s1.area());

b1.displayStatistics(b1.area());

2) s1.displayStatistics();

s1 = b1;

s1.displayStatistics();

b1.displayStatistics();

This is an legal assignment.

The area() method that the above assignment will invoke.

s1.displayStatistics(s1.area());

s1 = b1;

s1.displayStatistics(b1.area());

b1.displayStatistics(b1.area());

3) s1.displayStatistics();

b1 = s1;

s1.displayStatistics();

b1.displayStatistics();

This is an illegal assignment.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • This module focuses on the basics of Physical Security, Social Engineering, Network Vulnerabilities and Threats, Authentication,...
    asked 4 minutes ago
  • 6. For the given polynomial, find all zeros of the polynomial algebraically. Factor the polynomial completely....
    asked 4 minutes ago
  • What words or images come to mind when you think of disability?
    asked 11 minutes ago
  • Ajax entered into a four-year finance lease that specifies eight equal minimum semi-annual lease payments. Each...
    asked 11 minutes ago
  • A spherical tank, 1.5 m in diameter, is maintained at a temperature of 120 ◦C and...
    asked 12 minutes ago
  • Consider the salt, lead(II) iodate, Pb(IO3)2. Write the equilibrium reaction (with states), and the equilibrium-constant expression...
    asked 15 minutes ago
  • A 1963 Lincoln Continental travels northward at a speed of 25 m/s. When it enters an...
    asked 19 minutes ago
  • Let Z[x] be the ring of polynomials with integer coefficients. Find U(Z[x]), the set of all...
    asked 26 minutes ago
  • Regarding geotextiles used in roadway separation: What is the required burst pressure of a geotextile supporting...
    asked 46 minutes ago
  • [A] List all the structural features (chains, rings, functional groups, # of C's, rings, etc) the...
    asked 47 minutes ago
  • . Let Y1, ..., Yn denote a random sample from the exponential density function given by...
    asked 1 hour ago
  • The Oregon Department of Transportation (ODOT) released a request for proposals to widening/expanding a certain segment...
    asked 1 hour ago