Inheritance Class tutorial in Advance JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Inheritance Class Advance JavaScript</title>
    <link rel="stylesheet" href="">
</head>

<body>
    <script>
        class Employee {
            constructor(name, age, salary) {
                this.empname = name;
                this.empage = age;
                this.empsalary = salary;
                console.log("Constructor : Employee, " + name);
            }
            info() {
                console.log("Employee Name : " + this.empname);
                document.write(`<h3>Employee Class</h3>
                                Name : ${this.empname} <br>
                                Age : ${this.empage} <br>
                                Salary : ${this.empsalary} <br>`);
            }
        }
        class Manager extends Employee {
            // constructor(name) {
            //     super();
            //     console.log("Constructor : Manager, " + name);
            // }

            info() {
                super.info();
                console.log("Manager Name : " + this.empname);

                let ta = 1000;
                let pa = 300;
                let totalsalary = this.empsalary + ta + pa;

                document.write(`<h3>Manager Class</h3>
                                Name : ${this.empname} <br>
                                Age : ${this.empage} <br>
                                Salary : ${totalsalary} <br>`);
            }
        }
        class Test extends Manager {

        }
        let a = new Test("Hello Test", 25, 20000);
        // let b = new Employee("Ram Kumar", 22, 12000);
        a.info();
        // b.info();
    </script>
</body>

</html>










Comments

Popular posts from this blog

Symbols tutorial in Advance JavaScript

Async and Await Method tutorial in Advance JavaScript

String Methods in JavaScript