Question: Consider the following abstract class declaration. public abstract class 2DShape { abstract public double getArea(); public String toString() { return A shape with area +

Consider the following abstract class declaration.

public abstract class 2DShape { abstract public double getArea(); public String toString() { return A shape with area  + getArea(); } }

Which of the following class declarations correctly extend the abstract class 2DShape?

  1. public class Circle extends 2DShape { double r; // constructors not shown public double getArea() { return 3.14 * r * r; } public String toString() { return A circle with radius  + r; } }
  2. public class Triangle extends 2DShape { double b; double h; // constructors not shown public double getArea() { return b * h / 2; } }
  3. public class Polygon extends 2DShape { int numSides; // constructors not shown public int getArea() { return numSides; } public String toString() { return A polygon with  + numSides +  sides.; } }

A. I, II and III

B. I and II only

C. II only

D. I and III only

E. I only

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!