11.7k views
3 votes
2. You have classes to represent different shapes (see below). You realize you can benefit from inheritance and polymorphism by creating a superclass for all shapes. a. Create such a superclass. b. Did you choose an abstract class or an interface for your answer to part a? c. Why did you make this choice?

1 Answer

0 votes

Answer:

The description for the given question is described in the explanation section below.

Step-by-step explanation:

a...

interface Shape

{

public double getArea(); // creating a function

public double getPerimeter(); // creating a function

}

b and c...

  • I preferred Interface although abstract classes are being used when children's classes associate certain aspect methods and variables and because all classes represent a certain method throughout the specific solution, not instance variables, it would be easier to construct an interface.
  • Almost all of the period interfaces are favored because they have multiple inheritance capabilities.

User Karthik Kompelli
by
6.8k points