// whenever object is created , constructor is automatically called
class Employee {
constructor(givenName, givenExperience, givenDivision) {
this.name = givenName;
this.experience = givenExperience;
this.division = givenDivision;
}
slogan() {
return `my name is ${this.name}`;
}
static add(a, b) {
return a + b;
}
}
// creating object of Employee class
e = new Employee("himanshu", 45, "A&C");
// console.log(e);
// console.log(e.name);
// console.log(e.experience);
// console.log(e.slogan());
// console.log(Employee.add(5, 5));
class Programmer extends Employee {
constructor(givenName, givenExperience, givenDivision, givenLanguage) {
super(givenName, givenExperience, givenDivision);
this.language = givenLanguage;
}
favoriteLanguage() {
if (this.language == "Python")
return `good programmer with exp ${this.experience}`;
else
return `${this.name} is a bad programmer`;
}
static multiply(a, b) {
return a * b;
}
}
p = new Programmer("Piyush", 34, "DD", "Go");
console.log(p);
console.log(p.favoriteLanguage())
console.log(Programmer.multiply(3, 4));
0 Comments