Introduction

ES6 allows us to inherit static methods of a parent class.

Consider the following example where a static method of Bus is called on its derived class (SchoolBus):

Demo

class Bus { 
  static radio() { //w  ww.  j a v a2  s. c o m
       console.log("Radio works"); 
  } 
} 

class SchoolBus extends Bus {} 

SchoolBus.radio();

Result

Here, a new static radio() method is added to the Bus class.

Using inheritance, this method is available as SchoolBus.radio() and behaves in the same manner as the Bus.radio() method.

Related Topic