What will be the output of the following program?
import java.util.*;
class Shape {
int value;
public Shape(int value) {
this.value = value;
}
public int shape() {
return value + value;
}
}
class Car extends Shape {
public Car(int value) {
super(value);
}
public int shape() {
return value * value;
}
}
public class SuperClassAndSubClass {
public static void main(String arg[]) {
List<Car> shapes = new ArrayList<Car>();
shapes.add(new Car(12)); shapes.add(new Car(2));
Car[] shapesArray = new Car[2];
shapesArray[0] = new Car(12); shapesArray[1] = new Car(2);
SuperClassAndSubClass object = new SuperClassAndSubClass();
object.printShapesArray(shapesArray);
object.printShapesList(shapes);
}
public void printShapesList(List<Shape> shapes) {
System.out.println();
System.out.print("List :");
for (Shape shape : shapes) {
System.out.print(shape.shape() + " ");
}
}
public void printShapesArray(Shape[] shapes) {
System.out.print("Array :");
for (Shape shape : shapes) {
System.out.print(((Car) shape).shape() + " ");
}
}
}