In object-oriented computer programming, a metaclass is one whose instances are also classes. For instance, in Python, the built-in class type is a metaclass: instances of class type are themselves a class of objects.
The use of metaclasses is most prevalent in object-oriented languages in which classes are "first-class" objects; meaning they can be used just like any other object in the language:
- They can be named variables;
- They can be passed as an argument to methods, functions, and procedures;
- They can be returned as the result of a method, function, or procedure; and
- They can be included as part of a data structure.
It is possible, but uncommon, to implement metaclasses in C++ and Java. More commonly, metaclasses can be found in programs written in Python, Ruby, Smalltalk, Perl, Objective-C, and Common Lisp/CLOS.