Given the following superclass: abstract class Shape { private int sides; abstract double area(); int sides() { return sides; } } Write the following Shape subclasses with the correct instance variables, constructors and area method: (Use Java) Shape sides area rectangle 4 length * width triangle 3 (height * base) / 2 square 4 side * side
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Given the following superclass:
abstract class Shape {
private int sides;
abstract double area();
int sides() { return sides; }
}
Write the following Shape subclasses with the correct instance variables, constructors and area method: (Use Java)
Shape |
sides |
area |
rectangle |
4 |
length * width |
triangle |
3 |
(height * base) / 2 |
square |
4 |
side * side |
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)