Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started