Last active
March 18, 2019 15:28
-
-
Save attaradev/d32292bc86b315698c4490504f2027c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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