In object oriented computer programming, a class array can refer to one of two types of data structures. Some programmers use the term to describe a standard array data type made up of elements that are object instances of a given class. It also can be an encapsulated object of the class array, also known as a wrapper object, used in place of a scalar array to make a variety of methods available for use in managing the array. Although there might be more complex functionality, the wrapper array class is really no different in concept than wrapper objects for other scalar data types such as integers or characters. In both cases, the structure can only be used within the context of an object oriented programming language that supports classes.
The first definition of a class array identifies it as a standard array data type that is declared to hold objects instantiated from a single specific class. This is commonly done when holding a set series of objects, especially when the maximum number of objects is known so the array is not declared with an excessive amount of elements. The polymorphic mechanisms in object oriented programming means the use of a class array can be very dynamic, because it can hold a generic superclass, allowing a variety of subclasses to be held as elements despite their varying implementations. One complication when using a class array, however, can arise when the number of elements is unknown and either grows larger than the defined size of the array, or is very small, leaving wasted memory space allocated with the array. A solution is to use collection-type objects such as vectors or arraylists instead of a scalar array that cannot be resized.
The second definition of a class array is an object that contains a scalar array but also provides a number of methods to manipulate and change the array. Some languages implement very efficient sorting and searching algorithms within a class array wrapper. Another advantage in using an array that is implemented as a class is that the class can easily be passed and changed by different functions and methods, especially if the base array class is descended from a generic object class. The class array is often the basis for other types of array-based classes in a programming library, such as an arraylist or a hash table. Additionally, some languages allow the array class to be extended, meaning a user can redefine some of the basic methods with more specialized implementations while retaining the core functionality of the class.