AP Computer Science A Question of the Day

Test your knowledge with a hand-picked multiple-choice question.

Consider the following code:

public class Rectangle {

private double width, height;

public Rectangle(double w,double h) {

width = w;

height = h;

}

``

public double getArea() {

return width * height;

}

``

public double getPerimeter() {

return 2 * width + 2 * height;

}

}

``

public class Square {

private double side;

public Square(double s) {

side = s;

}

public double getArea() {

return side * side;

}

public double getPerimeter() {

return 4 * side;

}

}

Which of the following represents a redefinition of Square that utilizes the benefits of inheritance?

Select an answer and click Check.