Object - Inheritance

> Code - (Programming|Computer) Language > Language - Object

Table of Contents

1 - About

Inheritance is the process by which one class takes on the attributes and methods of another, and it's used to express an is-a relationship (Parent)

Object-oriented programming allows classes to inherit commonly used state and method (behaviour) from other classes.

A subclass inherits all of the public and protected members of its parent (superclass), no matter what package the subclass is in.

A class has exactly one direct superclass. A class inherits fields and methods from all its superclasses, whether direct or indirect. A subclass can override methods that it inherits, or it can hide fields or methods that it inherits.

Each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

Some language does not permit multiple inheritance, but interfaces provide an alternative.

Classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.

Composition is better than inheritance.

Advertising
code/object/inheritance.txt ยท Last modified: 2019/02/18 13:49 by gerardnico