Skip to content

Commit 38f2a07

Browse files
committed
exec: explain-the-concept-of-inheritance-in-es2015-classes
1 parent 3656d64 commit 38f2a07

File tree

1 file changed

+4
-4
lines changed
  • questions/explain-the-concept-of-inheritance-in-es2015-classes

1 file changed

+4
-4
lines changed

questions/explain-the-concept-of-inheritance-in-es2015-classes/en-US.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Explain the concept of inheritance in ES2015 classes
66

77
Inheritance in ES2015 classes allows one class to extend another, enabling the child class to inherit properties and methods from the parent class. This is done using the `extends` keyword. The `super` keyword is used to call the constructor and methods of the parent class. Here's a quick example:
88

9-
```js
9+
```js live
1010
class Animal {
1111
constructor(name) {
1212
this.name = name;
@@ -44,7 +44,7 @@ Inheritance in ES2015 classes allows a class (child class) to inherit properties
4444

4545
The `extends` keyword is used to create a class that is a child of another class. The child class inherits all the properties and methods of the parent class.
4646

47-
```js
47+
```js live
4848
class ParentClass {
4949
constructor() {
5050
this.parentProperty = 'I am a parent property';
@@ -75,7 +75,7 @@ child.parentMethod(); // This is a parent method
7575

7676
The `super` keyword is used to call the constructor of the parent class and to access its methods. This is necessary when you want to initialize the parent class properties in the child class.
7777

78-
```js
78+
```js live
7979
class Animal {
8080
constructor(name) {
8181
this.name = name;
@@ -108,7 +108,7 @@ dog.speak();
108108

109109
Child classes can override methods from the parent class. This allows the child class to provide a specific implementation of a method that is already defined in the parent class.
110110

111-
```js
111+
```js live
112112
class Animal {
113113
speak() {
114114
console.log('Animal makes a noise.');

0 commit comments

Comments
 (0)