Subclass (computer science)


Subclass (computer science)

In object-oriented programming, a subclass is a class that inherits some properties from its superclass.

You can usually think of the subclass as being "a kind of" its superclass, as in a "a Manx is a kind of cat", or "a square is a kind of rectangle":

*A cat has fur, four legs, and a tail
**A Manx cat does not have a tail, but has all of the other characteristics listed above
*A rectangle has four sides with lengths "w" and "h"
**A square has all of the characteristics of a rectangle; in addition, "w" = "h"

In this way, a subclass is a more specific version of its superclass; that is, the facts about the cat state what is generally true for all cats, even if some kinds of cats happen to have no tail. And while all rectangles have four sides, the square has the more restricted feature that all of its sides have the same length.

Don't confuse the subclass-superclass relationship with that of classes and instances. An "instance of cat" refers to "one particular cat". The Manx cat in the table is still a class — there are many instances of Manx cats. And if a particular cat (an instance of the cat class) happen to have its tail bitten off by a fox, that does not change the cat class. It's just that particular cat that has changed.

Subclasses and superclasses are often referred to as "derived" and "base" classes, respectively, terms coined by C++ creator Bjarne Stroustrup, who found these terms more intuitive than the traditional nomenclature. [Stroustrup, Bjarne. "The Design and Evolution of C++". Addison-Wesley. Reading, Mass. 1994. ISBN 0-201-54330-3. Page 49]

ee also

For a more in-depth explanation of the concept of classes in object-oriented programming, see class (computer science), in particular the section about subclasses and superclasses on that page.

*Virtual inheritance
*Top type
*Subtype

References


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Inheritance (computer science) — In object oriented programming, inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined. The inheritance concept was invented in 1967 for Simula. [ [http://heim.ifi.uio.no/… …   Wikipedia

  • Coupling (computer science) — In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules.Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa. The… …   Wikipedia

  • Object (computer science) — In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure. (With the later introduction of object oriented programming the same word,… …   Wikipedia

  • Superclass (computer science) — In computer science, a superclass is a class from which other classes are derived. A superclass is also called a parent class . The classes that are derived from a superclass are known as child classes , derived classes , or subclasses. We can… …   Wikipedia

  • Class (computer science) — In object oriented programming, a class is a programming language construct that is used as a blueprint to create objects. This blueprint includes attributes and methods that the created objects all share.More technically, a class is a cohesive… …   Wikipedia

  • Method (computer science) — In object oriented programming, the term method refers to a subroutine that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods). Like a procedure in… …   Wikipedia

  • Covariance and contravariance (computer science) — Within the type system of a programming language, covariance and contravariance refers to the ordering of types from narrower to wider and their interchangeability or equivalence in certain situations (such as parameters, generics, and return… …   Wikipedia

  • Subclass — may refer to:* Subclass (biology), a taxonomic rank intermediate between class and superorder * Subclass (computer science), a class that is derived from another class or classes * Subclass (database theory), a class which inherits its data… …   Wikipedia

  • Class (computer programming) — In object oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable …   Wikipedia

  • Coupling (computer programming) — In computer science, coupling or dependency is the degree to which each program module relies on each one of the other modules. Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa. The… …   Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.