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();
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.