According to the inheritance hierarchy in the following Figure 1, and the provided Shape class and Circle class: - area

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

According to the inheritance hierarchy in the following Figure 1, and the provided Shape class and Circle class: - area

Post by answerhappygod »

According To The Inheritance Hierarchy In The Following Figure 1 And The Provided Shape Class And Circle Class Area 1
According To The Inheritance Hierarchy In The Following Figure 1 And The Provided Shape Class And Circle Class Area 1 (255.49 KiB) Viewed 33 times
According to the inheritance hierarchy in the following Figure 1, and the provided Shape class and Circle class: - area (double) - color (String) - name (String) + Shape(String, String) + getArea(): Double Shape + getName(): String + setColor(String) + calArea() + printS tr(): String - radius (double) + Circle(String, String, double) + getRadius(): double + setRadius (double) +calArea() + printS tr(): String Figure 1. Inheritance hierarchy super(c, n); radius = r; Circle public class Circle extends Shape { private double radius; public Circle(String c, String n, double r) { radius = r; } public void setRadius(double r) { return radius; } public double getRadius() { public class Shape { } private double area; private String color; private String name; public Shape(String c, String n) { color = c; name = n; } public double getArea() { return area; } public String getName() { return name; } public void setColor(String c) { color = c; } public void calArea() { } area = 0; public String printStr() { return "name = " + name + "--" + "color = "+color+ "\n"; } } public void calArea() { area = Math.PI* radius*radius; //assume Math.PI is 3.14 }
public String printStr() { return "name = " + name + "--" + "color = "+color+ "--"+"area = "+area+"\n"; } }//endofCircle With Circle and Shape classes defined above, the follow codes are given: public class TestApp { public static void main(String args[]) { line 1 Shapes = new Shape("yellow", "rectangle"); line2. System.out.println(s.printStr()); line3. Circle cOne = new Shape("green", "circle1", 1.0); line4 cOne.calArea(); line5. System.out.println(cOne.printStr()); line6 Shape cTwo = new Circle("red", "circle 10", 10.0); line7. cTwo.calArea(); line8. } }//endof TestApp System.out.println(cTwo.printStr()); 1. Which line in TestApp program has an error? How to fix the error? After fixing the error, what is the output of the program? (6 points) 2. Which method(s) is (are) overridden (2 points)? Which method(s) is (are) overloaded? (2 points) Put your answers in the answer area.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply