college.js / and Concept of Inheritence

 


// this is the parent class and the super() function will invoke and inherit this class
class Person {
constructor(n, dob, add, ph, dept, yoj,) {

this.name = n;
this.dateOfBirth = dob;
this.address = add;
this.phoneNumber = ph;
this.department = dept;
this.yearOfJoining = yoj;
}

updateAddress(newAddress) {

this.address = newAddress;

}

updatePhoneNumber(newPhoneNumber) {

this.phoneNumber = newPhoneNumber;
}

}

// This is the student class

// extends keyword will lend all the attributes and methods of Person class to Student class
class Student extends Person {

constructor(n, dob, add, ph, dept, programme, yoj, totalfee, feepaid) {

super(n, dob, add, ph, dept, yoj) // invoking the parent class Person

// These three are the some specific attributes only for Student class
this.programme = programme;
this.totalfee = totalfee;
this.feepaid = feepaid;
}

payFee(amount) {

this.feepaid += amount;
}

}


// This is the Professor class

// extends keyword will lend all the attributes and methods of Person class to Professor class
class Professor extends Person {

constructor(n, dob, add, ph, dept, yoj, qualification, salary) {

super(n, dob, add, ph, dept, yoj) // invoking the parent class Person

// These two attributes are only specific to Professor class
this.qualification = qualification;
this.salary = salary;

}

}

// Professor1 is an instance/ Object of Professor class only
let Professor1 = new Professor("Nobin", 2000, "Delhi", "3895", "Economics", 2024, "Phd",
3000000)
// invoking the class Professor

console.log(Professor1.address); // Delhi

Professor1.updateAddress("Roorke"); // updating Professor1 address from Delhi to Roorke

console.log(Professor1.address); // Roorke

/////////////////////////////////////////////////////////////////////////////////////////////
TERMINAL:












Comments

Popular posts from this blog

car.js

movie.js