IHadEnaughOfObjects
This commit is contained in:
@ -89,4 +89,76 @@ underwear.displayProduct();
|
||||
underwear.displayPrice();
|
||||
underwear.calculateTotal();
|
||||
|
||||
//https://youtu.be/lfmg-EJ8gm4?si=KJ_EBH2FxCEtonyR&t=19910
|
||||
//https://youtu.be/lfmg-EJ8gm4?si=KJ_EBH2FxCEtonyR&t=19910
|
||||
|
||||
|
||||
|
||||
//INHERITANCE
|
||||
|
||||
class Animals{
|
||||
alive = true
|
||||
constructor(name, age){
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
eat(){
|
||||
console.log(`This ${this.name} is eating`);
|
||||
}
|
||||
|
||||
sleep(){
|
||||
console.log(`This ${this.name} is sleeping`);
|
||||
}
|
||||
move(){
|
||||
console.log(`The ${this.name} is mowing with ${this.speed} km/h!!`)
|
||||
}
|
||||
}
|
||||
|
||||
class Rabbit extends Animals{
|
||||
constructor(name, age, speed){
|
||||
super(name, age);
|
||||
this.speed = speed;
|
||||
}
|
||||
run(){
|
||||
console.log(`This ${this.name} is running`);
|
||||
}
|
||||
set sname(newName){
|
||||
this._name = newName
|
||||
}
|
||||
get _name(){
|
||||
return this._name
|
||||
}
|
||||
}
|
||||
|
||||
class Fish extends Animals{
|
||||
constructor(name, age, speed){
|
||||
super(name, age);
|
||||
this.speed = speed;
|
||||
}
|
||||
swim() {
|
||||
console.log(`This ${this.name} is swimming like a rabbit, hopping through the water!`);
|
||||
}
|
||||
}
|
||||
|
||||
class Hawk extends Animals{
|
||||
constructor(name, age, speed){
|
||||
super(name, age); //BEFORE constructing the child we NEED to construct the parent with the super() function!!!
|
||||
this.speed = speed;
|
||||
}
|
||||
}
|
||||
|
||||
let fish = new Fish("izé", 4, 25);
|
||||
const rabbit = new Rabbit("nyuszi",5 ,23 );
|
||||
const hawk = new Hawk("Man", 5, 80);
|
||||
|
||||
console.log(fish.alive)
|
||||
fish.eat();
|
||||
rabbit.sleep();
|
||||
rabbit.run();
|
||||
hawk.sleep();
|
||||
console.log(hawk.speed);
|
||||
|
||||
rabbit.move();
|
||||
fish.move();
|
||||
hawk.move();
|
||||
|
||||
|
Reference in New Issue
Block a user