3. Given this code snippet, what will be the output?
interface Shape { double area(); }
class Rectangle implements Shape {
double width, height;
Rectangle(double w, double h) { width = w; height = h; }
public double area() { return width * height; }
}
class Circle implements Shape {
double radius;
Circle(double r) { radius = r; }
public double area() { return 3.14 * radius * radius; }
}
class AreaCalculator {
double totalArea(Shape[] shapes) {
double total = 0;
for (Shape s : shapes) total += s.area();
return total;
}
}
public class Main {
public static void main(String[] args) {
Shape[] shapes = { new Rectangle(2,3), new Circle(1) };
System.out.println(new AreaCalculator().totalArea(shapes));
}
}