Computer Science, asked by guuuttf5677, 1 month ago

what do you mean by array of objects​

Answers

Answered by dhyeypipalia2457
1

Answer:

An array of objects, all of whose elements are of the same class, can be declared just as an array of any built-in type. Each element of the array is an object of that class. Being able to declare arrays of objects in this way underscores the fact that a class is similar to a type.

Answered by piravinkumar00710
1

Answer:

An array of objects, all of whose elements are of the same class, can be declared just as an array of any built-in type. Each element of the array is an object of that class. Being able to declare arrays of objects in this way underscores the fact that a class is similar to a type.

Declaring Arrays of Objects

The simplest way to create an array of Frame objects is with the following declaration:

Frame windowList[5]; // an array of 5 Frame objects

An important aspect of declaring arrays of objects in this way is that all of the objects in the array must be constructed in the same way. It is not possible with this declaration to give each different object in the array a different set of constructor values. Furthermore, since no constructor arguments are given, the class must contain a constructor that has no arguments. Arrays of this form are useful when all of the objects should be constructed in a uniform way or when the "real" constructor information will not be know until sometime during the computation. In the later case, the array can be declared and the individual objects manipulated when the information is discovered. For example, the user may be asked to supply the name of a file which contains the desired locations and shapes for each of the windowList objects. This information can be read and each array element can then be moved and resized accordingly.

In other cases, it is desired that each of the objects in an array be specifically and individually constructed at the time the array is declared. This can be done as follows:

Frame windowList[5] = {Frame("Window 0", 0, 100, 100, 100),

Frame("Window 1", 25, 100, 100, 100),

Frame("Window 2", 50, 100, 100, 100),

Frame("Window 3", 75, 100, 100, 100),

Frame("Window 4", 100, 100, 100, 100)

};

Similar questions