Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions