Encyclopedia > Class (object-oriented programming)

  Article Content

Class (object-oriented programming)

A class is a kind of template (not to be confused with a C++ template, however) that describes the underlying structure of a group of objects. It could be said that a class is a blueprint, and an object is a house. An object belonging to a class is also called an instance of that class. If humanity were a class, then [you] would be an instance of the class [humanity].

A class specifies the data items each object of the class contains and the operations or methods that can be performed on each object belonging to the class (in object-oriented languages that lack generic functions).

(Some languages have objects but no classes. In these languages, objects are not restricted to structure provided by classes, and can be changed at will. This less common technique is called object-based programming.)

Subclasses and Superclasses

Classes are often related in some way. The most popular of these relations is inheritance, which involves subclasses and superclasses, also known respectively as child classes (or derived classes) and parent classes (or base classes). If [cars] was a class, then [Jaguar] and [Porsche] might be two sub-classes. If [Button] is a subclass of [Control], then all buttons are controls.

Some programming languages (for example C++) allow multiple inheritance - they allow a child class to have more than one parent class. This technique has been criticized by some for its unnecessary complexity and being hard to implement efficiently, though some projects have undoubtedly benefited from its use. Java, for example has no multiple inheritance, its designers feeling that this would be more trouble than it was worth.

Because the Microsoft Windows API was originally designed in an object-oriented way, each window is an instance of a class called the "window class".

Sub- and superclasses are considered to exist within a hierarchy.

See also: hierarchy, object-oriented programming, abstract class

For related meanings of the word "class", see Class. For other uses of the word class within computer science, see Class (computer science)



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Rameses

... also spelled Rameses, is the name of several Egyptian pharaohs: Ramses I[?] Ramses II ("The Great") Ramses III Ramses IV[?] The name means "Child of the Sun". ...

 
 
 
This page was created in 24.3 ms