Skip to content

Instantly share code, notes, and snippets.

@Oluwafayokemi
Last active January 8, 2019 18:14
Show Gist options
  • Select an option

  • Save Oluwafayokemi/a79d3dd362999a2af250e82ec6abaf75 to your computer and use it in GitHub Desktop.

Select an option

Save Oluwafayokemi/a79d3dd362999a2af250e82ec6abaf75 to your computer and use it in GitHub Desktop.
OOP- Aircraft
"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