Skip to content

Instantly share code, notes, and snippets.

@attaradev
Last active March 18, 2019 15:28
Show Gist options
  • Select an option

  • Save attaradev/d32292bc86b315698c4490504f2027c4 to your computer and use it in GitHub Desktop.

Select an option

Save attaradev/d32292bc86b315698c4490504f2027c4 to your computer and use it in GitHub Desktop.
class Person {
constructor(firstName, lastName, age) {
this._firstName = firstName;
this._lastName = lastName;
this._age = age;
}
getName() {
return `${this._firstName} ${this._lastName}`;
}
describe() {
return `Hello, I am ${this.getName()}`;
}
static shout() {
return "HAAAAAAY";
}
}
class Student extends Person {
constructor(firstName, lastName, age, ...courses) {
super(firstName, lastName, age);
this._courses = courses;
}
gotoClass() {
return `I am going to class to learn.`;
}
}
class Teacher extends Person {
constructor(firstName, lastName, age, course) {
super(firstName, lastName, age);
this._course = course;
}
getCourse() {
return this._course;
}
describe() {
return `Hello, I am ${this.getName()}. I teach ${this.getCourse()}`;
}
gotoClass() {
return `I am going to class to teach.`;
}
}
const teacher = new Teacher("Mike", "Attara", 24, "Maths");
console.log(teacher.describe());
const student = new Student("Mike", "Attara", 24, "Maths", "English");
console.log(student.describe());
console.log(teacher.gotoClass());
console.log(student.gotoClass());
console.log(Person.shout());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment