Subclass (computer science)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

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. Some [1] point out that squares may be a type of rectangle mathematically but are rarely desired to be treated as such in computer programs since changing the width of a rectangle does not change its height whereas this is the case for a square.

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.[2]

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.

  1. ^ Sutter, Herb. Exceptional C++. Addison-Wesley. Reading, Mass. 1999. ISBN 0-201-61562-2. Page 95
  2. ^ Stroustrup, Bjarne. The Design and Evolution of C++. Addison-Wesley. Reading, Mass. 1994. ISBN 0-201-54330-3. Page 49
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.