A property in programming known as inheritance, by virtue of which a class can derive the methods and properties of other class analogous to parent-child relationship in living beings. A child inherits its characteristics from its parents but it doesn’t work the other around. Also, similar to the parent-child relationship of living beings, a child can have its own properties too in addition to inherited ones. In the programming context, the class that derives from other classes is known as derived or sub or child class. Whereas, the class from which characteristic is derived is known as the base or super or parent class.
The concept of inheritance, sub, and superclass is same in all programming languages the only difference being their implementation. The objective here is to call a function defined in parent class with the help of child class. To obtain this result following methods listed can be used.
Direct calling method: Since a derived class has access to all characteristics of its base class, using child class’s object to refer to parent class’s function makes perfect sense.
Output: Two times will pop out that alert one time by using the parent’s object and other time by using the child’s object.
Using super Method: The super keyword is used in JS to call functions and constructors from parent class. Where ever super is mentioned in the child class the compiler looks for the specified function in its parent’s class. This is mostly used when functions are overloaded and a certain requirement asks for parent’s version of the function. It is also used to overload constructors
Calling method & Constructor: In this program we call method and constructor from child class.
- Call a parent window function from an iframe
- How to apply style to parent if it has child with CSS?
- jQuery | parent > child Selector
- How to find the parent class name with known class in jQuery ?
- How to remove parent element except its child element using jQuery ?
- How to communicate from parent component to the child component in Angular 9 ?
- How to navigate to a parent route from a child route?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.