Answers for "TypeScript Class Inheritance Example"

1

TypeScript Class Inheritance Example

class Animal {  private name: string;  constructor(theName: string) {    this.name = theName;  }}
class Rhino extends Animal {  constructor() {    super("Rhino");  }}
class Employee {  private name: string;  constructor(theName: string) {    this.name = theName;  }}
let animal = new Animal("Goat");let rhino = new Rhino();let employee = new Employee("Bob");
animal = rhino;animal = employee;Type 'Employee' is not assignable to type 'Animal'.
  Types have separate declarations of a private property 'name'.2322Type 'Employee' is not assignable to type 'Animal'.
  Types have separate declarations of a private property 'name'.Try
Posted by: Guest on July-14-2021

Code answers related to "TypeScript Class Inheritance Example"

Browse Popular Code Answers by Language