Last active
January 8, 2019 18:14
-
-
Save Oluwafayokemi/a79d3dd362999a2af250e82ec6abaf75 to your computer and use it in GitHub Desktop.
OOP- Aircraft
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
| "use strict"; | |
| class AirCraft{ | |
| constructor(name, speed, altitude, capacity){ | |
| this.name = name; | |
| this.speed = speed; | |
| this.altitude = altitude; | |
| this.capacity = capacity; | |
| } | |
| /*inheritance*/ | |
| getAirCraft(){ | |
| return `${this.name} | ${this.speed}km/hr A :: ${this.altitude}ft C:: ${this.capacity}ps `; | |
| } | |
| } | |
| /* polymorphism*/ | |
| class FighterJet extends AirCraft { | |
| constructor(name, speed, altitude, capacity){ | |
| super(name, speed, altitude, capacity); | |
| } | |
| } | |
| class WarCraft extends AirCraft{ | |
| constructor(name, speed, altitude, capacity){ | |
| super(name, speed, altitude, capacity); | |
| } | |
| getAirCraft(weapons){ | |
| return `${this.name} | ${this.speed}km/hr A :: ${this.altitude}ft C:: ${this.capacity}ps with Weapons: ${weapons}`; | |
| } | |
| } | |
| /*encapsulation*/ | |
| const craft = new AirCraft('Arik', 885, 39000, 100); | |
| console.log(craft.getAirCraft()); | |
| const fJet = new FighterJet('Navy', 1000, 39000, 200); | |
| console.log(fJet.getAirCraft()); | |
| const war = new WarCraft('Army', 500, 9000, 100); | |
| console.log(war.getAirCraft('Guns')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment