Inheritance in JavaScript

What you will learn here about JavaScript

  • Inheritance in JavaScript

Inheritance in JavaScript

One class extending or accessing properties or methods of another class is nothing but the inheritance. In JavaScript inheritance is acheived by using keyword extends.

Syntax of inheritance:

class subclass_name extends superclass_name
{}

Class whose properties are accessing in another class is called as super class or base class or parent class.

Class which accessing properties of another class is called as sub class or derived class or child class

<script>
//Parent class
class Mobile
{
constructor()
{}
calling()
{
document.getElementById(‘result’).innerHTML=”We are in calling function”;
}
}
//Child class
class Vivo extends Mobile
{
constructor()
{
super();
}
}const object=new Vivo(); //child class object creation
object.calling();
</script>


You may also like...