sudhakarinfotech
(current)
Run Code
Live Code Editor- Super Keyword Example In Javascript
Source Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Javascript Class Inheritance</title> </head> <body> <h1>Javascript Class Inheritance</h1> <script type="text/javascript"> class Person { constructor(name,age) { this.name = name; this.age = age; } greet() { document.write('Name:'+this.name+ ' Age: '+this.age); } } class Teacher extends Person { constructor(name,age,height) { super(name,age); this.height = height; } additionInfo(){ document.write('Your height is '+this.height); } } let teacher1 = new Teacher('Jack',25,5); teacher1.greet(); document.write("<br>"); teacher1.additionInfo(); </script> </body> </html>
Source Code Output :
Running