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?
-
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; } } -
public class Triangle extends 2DShape { double b; double h; // constructors not shown public double getArea() { return b * h / 2; } } -
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
Get step-by-step solutions from verified subject matter experts
