Sub Classes

// Create a simple Person class with a constructor
class Person{
    constructor(firstName, lastName){
        this.firstName = firstName;
        this.lastName = lastName;
    }
    greeting(){
        return `Hello there ${this.firstName} ${this.lastName}`;
    }
}

class Customer extends Person{
    constructor(firstName, lastName, phone, membership){
        // Calls the parent class constructor
        super(firstName, lastName);

        this.phone = phone;
        this.membership = membership;
    }

    // Static method
    static getMembershipCost(){
        return 500;
    }
}

const john = new Customer('Joe', 'Dawson', '555-555-5555', 'Standard');

console.log(john.greeting());

console.log(Customer.getMembershipCost())
Was this page helpful?

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *