How can I use object array in java ?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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.

5th Mar 2020, 7:52 PM
Sourav Bhunia
Sourav Bhunia - avatar
2 Réponses
5th Mar 2020, 8:32 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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.
5th Mar 2020, 8:06 PM
Tibor Santa
Tibor Santa - avatar