Articles → JAVASCRIPT → Class Inheritance In Javascript
Class Inheritance In Javascript
Example
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
class BaseClass {
Print() {
alert("Print message of the BaseClass");
}
}
class DerivedClass extends BaseClass {
Print1() {
alert("Print message of the Derived Class");
}
}
let cls = new DerivedClass();
cls.Print();
cls.Print1();
</script>
</head>
<body>
</body>
</html>
Calling The Constructors Of Base And Derived Class
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
class BaseClass {
constructor() {
alert("Constructor of the base class");
}
}
class DerivedClass extends BaseClass {
constructor() {
super();
alert("Constructor of the derived class");
}
}
let cls = new DerivedClass();
</script>
</head>
<body>
</body>
</html>