Problem

Recall the classessphere and Ball, as described in this chapter in the section “Inheritanc...

Recall the classessphere and Ball, as described in this chapter in the section “Inheritance Revisited,” and consider the following variation:

public class Sphere {

public double area() { // surface area

} // end area

public void displayStatistics() {

} // end displayStatistics

} // end Sphere

class Ballextends Sphere {

public double area)) { // cross-sectional area

// Cross-sectional area is used to compute drag

//on the ball

} // end area

public void displayStatistics() {

} // end displayStatistics

}// end Ball

Suppose that different implementations of displayStatistics appear in both Sphere and Ball and they each invoke the method area. Also assume that bl and s1 are declared as follows:

Sphere s1 = new Sphere();

Ball bl = new Ball();

For each of the scenarios shown next, indicate if the assignments are legal or illegal. In addition, if the assignments are legal, also explain which version of area eachcall to displayStatistics invokes. Be sure to explain your answer. Assume thateach set of statements is independent and begins with the previous declarations.

a. s1.displayStatistics();

bl.displayStatistics();

b. s1.displayStatistics();

s1 = bl;

s1.displayStatistics();

bl.displayStatistics();

C. bl.displayStatistics();

bl = s1;

s1.displayStatistics();

bl.displayStatistics();

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