Skip to content
Advertisement

How to override function/value in a class thats has been extended

A little confused on how to over ride a return value in a function.

Example.

class Customer {
   getFirstName() {
        return this.firstName;
    }
}

and I have another class that extends the above class. What I am aiming to do is if getFirstName is called from Customer, then itll return a value. If however getFirstName is called from Client, I want it to return null.

class Client extends Customer {
    //TODO
}

How would I go about this?

Advertisement

Answer

just override and return null in client class

class Client extends Customer {
         getFirstName() {
            return null
         }
    }
Advertisement