Question: Consider the following declaration for a class that will be used to represent rectangles. public class Rectangle { private double height; private double width; public

Consider the following declaration for a class that will be used to represent rectangles.

public class Rectangle { private double height; private double width; public Rectangle() { height = 2.0; width = 1.0; } public Rectangle(double w, double h) { height = h; width = w; } public double getHeight() { return height; } public double getWidth() { return width; } public void setHeight(double h) { height = h; } public void setWidth(double w) { width = w; } //Other methods not shown }

A Square class which extends the Rectangle class is to be written. Which of the following constructors will cause an error upon compilation when added to this class?

(A) public Square() { super(1.0, 1.0); }

(B) public Square(double w) { height = w; width = w; }

(C) public Square() { setHeight(1.0); setWidth(1.0); }

(D) public Square(double w) { super(w, w); }

(E) public Square(double w) { super(); setHeight(w); setWidth(w); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!