Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is an Inheritance | Inheritance
Object-Oriented Programming in JavaScript
course content

Contenido del Curso

Object-Oriented Programming in JavaScript

Object-Oriented Programming in JavaScript

1. Classes & Objects
2. Encapsulation
3. Static
4. Inheritance

bookWhat is an Inheritance

Inheritance is another main OOP principle, which means that some classes can adopt properties of other classes, and maybe extend them.

Like, for example, we have class Rectangle which represents the rectangle instance. Then, let’s define class Square. Square is a Rectangle, too, so we can create this class from the Rectangle class. Use keyword extends:

123456789101112
class Rectangle { height; width; constructor(height, width) { this.height = height; this.width = width; console.log('Rectangle created'); } } class Square extends Rectangle{ }
copy

Now Square has the same attributes and methods as Rectangle class.

The Rectangle is a base class, and Square is a derived class. Or you can say that Rectangle is a parent class and Square is a daughter class.

Square differs with sides length: height is equal to the width, unlike for Rectangle.

Usually, JavaScript classes such as an array, console, window, etc. inherit some base classes, which can inherit other classes. It is very advisable to extend existing classes, not to define similar classes again.

Tarea

Create Fruit and Apple class, such that Apple is a daughter class for Fruit class. Let these classes be empty for now.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 1
toggle bottom row

bookWhat is an Inheritance

Inheritance is another main OOP principle, which means that some classes can adopt properties of other classes, and maybe extend them.

Like, for example, we have class Rectangle which represents the rectangle instance. Then, let’s define class Square. Square is a Rectangle, too, so we can create this class from the Rectangle class. Use keyword extends:

123456789101112
class Rectangle { height; width; constructor(height, width) { this.height = height; this.width = width; console.log('Rectangle created'); } } class Square extends Rectangle{ }
copy

Now Square has the same attributes and methods as Rectangle class.

The Rectangle is a base class, and Square is a derived class. Or you can say that Rectangle is a parent class and Square is a daughter class.

Square differs with sides length: height is equal to the width, unlike for Rectangle.

Usually, JavaScript classes such as an array, console, window, etc. inherit some base classes, which can inherit other classes. It is very advisable to extend existing classes, not to define similar classes again.

Tarea

Create Fruit and Apple class, such that Apple is a daughter class for Fruit class. Let these classes be empty for now.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 1
toggle bottom row

bookWhat is an Inheritance

Inheritance is another main OOP principle, which means that some classes can adopt properties of other classes, and maybe extend them.

Like, for example, we have class Rectangle which represents the rectangle instance. Then, let’s define class Square. Square is a Rectangle, too, so we can create this class from the Rectangle class. Use keyword extends:

123456789101112
class Rectangle { height; width; constructor(height, width) { this.height = height; this.width = width; console.log('Rectangle created'); } } class Square extends Rectangle{ }
copy

Now Square has the same attributes and methods as Rectangle class.

The Rectangle is a base class, and Square is a derived class. Or you can say that Rectangle is a parent class and Square is a daughter class.

Square differs with sides length: height is equal to the width, unlike for Rectangle.

Usually, JavaScript classes such as an array, console, window, etc. inherit some base classes, which can inherit other classes. It is very advisable to extend existing classes, not to define similar classes again.

Tarea

Create Fruit and Apple class, such that Apple is a daughter class for Fruit class. Let these classes be empty for now.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Inheritance is another main OOP principle, which means that some classes can adopt properties of other classes, and maybe extend them.

Like, for example, we have class Rectangle which represents the rectangle instance. Then, let’s define class Square. Square is a Rectangle, too, so we can create this class from the Rectangle class. Use keyword extends:

123456789101112
class Rectangle { height; width; constructor(height, width) { this.height = height; this.width = width; console.log('Rectangle created'); } } class Square extends Rectangle{ }
copy

Now Square has the same attributes and methods as Rectangle class.

The Rectangle is a base class, and Square is a derived class. Or you can say that Rectangle is a parent class and Square is a daughter class.

Square differs with sides length: height is equal to the width, unlike for Rectangle.

Usually, JavaScript classes such as an array, console, window, etc. inherit some base classes, which can inherit other classes. It is very advisable to extend existing classes, not to define similar classes again.

Tarea

Create Fruit and Apple class, such that Apple is a daughter class for Fruit class. Let these classes be empty for now.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 4. Capítulo 1
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt