Answered step by step
Verified Expert Solution
Link Copied!

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?

  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

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

Students also viewed these Databases questions

Question

What is quality of work life ?

Answered: 1 week ago

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago