Brief introduction to Inheritance and Polymorphism

노승광
Research Team — DAWN
2 min readNov 7, 2021

--

Inheritance

Instance of child class can access both data and behavior of parent class. We can say the child ‘inherits’ its parent.

Using the content of inheritance programmers can organize the classes into a hierarchical structure. More practically, to elaborate inheritance, we can say member variables and functions in the parent class are part of child class.

Since the behavior of a child class is larger than the behavior of the parent, we can say that the child is an extension of the parent. In contrast, because the child can override behavior to make it do something the parent cannot do, we can also say the child is a contraction of the parent. Therefore, inheritance is both extension and contraction at the same time. This is the power of object oriented programming; interaction between extension and contraction allows OOP systems to take very general tools and specialize them for specific projects.

Inheritance also allows programmers to easily reuse the code. Methods defined in the parent can be reused by the child. Consequently, creating new abstractions becomes easier.

Polymorphism

The meaning of polymorphism can be guessed from the name itself. ‘poly’ means ‘many’ and ‘Morph’ means ‘forms’. Therefore, polymorphism can be translated to easier word as ‘many-forms’.

As ‘many-forms’ suggests, polymorphism means ‘one name having many different meangins’.

There are several forms of polymorphisms; overloading, overriding, polymorphic variable and generics.

Overloading means a single function name having several alternative implementations. Overriding means different definitions that use the same method name with the same signature. Polymorphic variable means a variable declared as one type but holding a value of a different type. Lastly, generic means a way of creating general tools or classes by parameterizing on types.

--

--