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
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
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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);

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education