Subclass (computer science)
Encyclopedia : S : SU : SUB : 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
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
See 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.
References
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
