0

Lets say we have a class of Animal,

class Animal {
    name: string;

    constructor(name: string) {
        this.name = name;
    }

    eat() {
        console.log(this.name + " is a Animal and is eating");
    }
}

and a class of Robot,

class Robot {
    name: string;

    constructor(name: string) {
        this.name = name;
    }
}

then how is this possible to have an instance of Animal having type of Robot class..

let r0: Robot = new Animal("Donkey"); //how is this possible?

and also note the in the animal class there is an extra method so how is it possible?

AsimRazaKhan
  • 2,154
  • 3
  • 22
  • 36

0 Answers0