Sort out the classes

Report a typo

You are given 4 classes — Shape, Polygon, Square, Circle.

Classes Polygon and Circle both extend the class Shape, the class Square extends the class Polygon.

You need to implement a method that takes Shape array and adds every element to one of the provided Lists based on their class.

Write a program in Java 17
class Sort {
public static void sortShapes(Shape[] array,
List<Shape> shapes,
List<Polygon> polygons,
List<Square> squares,
List<Circle> circles) {
// write your code here
}
}

//Don't change classes below
class Shape { }
class Polygon extends Shape { }
class Square extends Polygon { }
class Circle extends Shape { }
___

Create a free account to access the full topic