You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: questions/explain-the-concept-of-inheritance-in-es2015-classes/en-US.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: Explain the concept of inheritance in ES2015 classes
6
6
7
7
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:
8
8
9
-
```js
9
+
```js live
10
10
classAnimal {
11
11
constructor(name) {
12
12
this.name= name;
@@ -44,7 +44,7 @@ Inheritance in ES2015 classes allows a class (child class) to inherit properties
44
44
45
45
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.
46
46
47
-
```js
47
+
```js live
48
48
classParentClass {
49
49
constructor() {
50
50
this.parentProperty='I am a parent property';
@@ -75,7 +75,7 @@ child.parentMethod(); // This is a parent method
75
75
76
76
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.
77
77
78
-
```js
78
+
```js live
79
79
classAnimal {
80
80
constructor(name) {
81
81
this.name= name;
@@ -108,7 +108,7 @@ dog.speak();
108
108
109
109
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.
0 commit comments