Quick actions

cmd+k|ctrl+k

Navigation

Languages

Kuis Coding: OOP Dicoding

Snippet info

Language

JavaScript

Visibility

public

Author

ryandfbasketball12

Created

2022-10-23T03:24:13.30826Z

Updated

2022-10-23T03:24:13.30826Z

class Animal {
    constructor(name, age, isMammal) {
        this.name = name,
        this.age = age,
        this.isMammal = isMammal
    }
}

class Rabbit extends Animal {
    constructor(name, age) {
        super(name, age, true)
    }

    eat() {
        console.log(`${this.name} sedang makan`)
    }
}
class Eagle extends Animal {
    constructor(name, age) {
        super(name, age, false)
    }

    fly() {
        console.log(`${this.name} sedang terbang`)
    }
}

const myRabbit = new Rabbit('Labi', 2);
const myEagle = new Eagle('Elo', 4);
myRabbit.eat();
myEagle.fly();
INFO