Figure 10-18 Rectangle and Cube classes Rectangle - length : double - width : double + Rectangle(len : double, w : double) + setLength(len : double) : void + setWidth(w : double) : void + getLength() : double + getWidth() : double + getArea() : double Cube - height : double + Cube(len : double, w : double, h: double) + getHeight() : double + getSurfaceArea() : double + getVolume() : double

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

Recall the Rectangle and Cube classes discussed earlier, as shown in Figure 10-18.

a) Is the following statement legal or illegal? If it is illegal, why?
Rectangle r = new Cube(10, 12, 5);
b) If you determined that the statement in part a is legal, are the following statements
legal or illegal? (Indicate legal or illegal for each statement.)
System.out.println(r.getLength());
System.out.println(r.getWidth());
System.out.println(r.getHeight());
System.out.println(r.getSurfaceArea());
c) Is the following statement legal or illegal? If it is illegal, why?
Cube c = new Rectangle(10, 12);

Figure 10-18 Rectangle and Cube classes
Rectangle
- length : double
- width : double
+ Rectangle(len : double, w : double)
+ setLength(len : double) : void
+ setWidth(w : double) : void
+ getLength() : double
+ getWidth() : double
+ getArea() : double
Cube
- height : double
+ Cube(len : double, w : double,
h: double)
+ getHeight() : double
+ getSurfaceArea() : double
+ getVolume() : double
Transcribed Image Text:Figure 10-18 Rectangle and Cube classes Rectangle - length : double - width : double + Rectangle(len : double, w : double) + setLength(len : double) : void + setWidth(w : double) : void + getLength() : double + getWidth() : double + getArea() : double Cube - height : double + Cube(len : double, w : double, h: double) + getHeight() : double + getSurfaceArea() : double + getVolume() : double
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Events
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT