0
How can I use object array in java ??
Create an abstract class called shape to model a three dimensional shape. Derive classes cube and cone. Let user specify the size. The user may specify many items of the same shape. All the instances of each shape should be stored into a single array. Write a program to calculate area and volume of each shape.
2 Réponses
+ 1
Shape[] shapes = new Shape[5];
shapes[0] = new Cube(2);
If Cube is a subclass of Shape, then you can store Cube objects, as well as Cone objects, in the same Shape array.