1.

How Do You Implement Inheritance In Typescript?

Answer»

USING extends KEYWORD, we can implement INHERITANCE.

class Animal {
public domestic:boolean;
constructor(public name: string) { }
}

class Cat extends Animal {
constructor(name: string, domestic: boolean) 

super(name); 
this.domestic = TRUE;
}
}

class TIGER extends Animal {
constructor(name: string, domestic: boolean) 

super(name); 
this.domestic = false;
}
}

Using extends keyword, we can implement inheritance.

class Animal {
public domestic:boolean;
constructor(public name: string) { }
}

class Cat extends Animal {
constructor(name: string, domestic: boolean) 

super(name); 
this.domestic = true;
}
}

class Tiger extends Animal {
constructor(name: string, domestic: boolean) 

super(name); 
this.domestic = false;
}
}



Discussion

No Comment Found