javascript

Javascript: Class Inheritance

Inheritance is an important concept in Object Oriented Programming.

Inheritance is the process whereby one class, also called the sub-class, acquires the properties and methods of another class, also known as the super class.

To create a class inheritance in Javascript, we use the “extends” keyword.

class Animal{
 constructor(name){
        this.name = name;
    }
 sound(){
        console.log(`${this.name} makes sound`)
    }
}

class Cat extends Animal{
    myCat(){
        super.sound()
    }
}

let cat = new Cat("Fuzzy");
console.log(cat.myCat()); //Fuzzy makes sound

Notice that we use the “super” keyword to access the method from the parent class.

The class “Cat” now acquires the method of the super class “Animal”

Recent Posts

Cloudinary vs. AWS vs. ImageKit.io vs. Cloudflare

Choosing the right asset management service is vital. Cloudinary is frequently mentioned, but how does…

6 days ago

How to Integrate Cloudinary with PHP

Cloudinary is a powerful cloud-based media management platform that allows you to upload, store, manage,…

1 week ago

Trump Extends U.S. TikTok Sale Deadline to September 2025

In a surprising turn of events, former President Donald Trump announced on June 19, 2025,…

3 weeks ago

Master React Native Flexbox

Flexbox is a powerful layout system in React Native that allows developers to create responsive…

3 weeks ago

Getting Started With TensorFlow

"The journey of a thousand miles begins with a single step." — Lao Tzu Welcome…

4 weeks ago

Your Mind is a Supercomputer

We often describe ourselves as "processing" information, "rebooting" after a bad day, or feeling "overloaded"…

4 weeks ago