Rather, isCitrus should be this.isCitrus . On the main show ...
Abstract methods must be visible to subclasses because you require the subclass to execute this method.
abstract class Fruit { name: string; constructor (name: string) { this.name = name } protected abstract hiFrase(): string; } class Apple extends Fruit { isCitrus: boolean; constructor(name: string, isCitrus: boolean) { super(name); this.isCitrus = isCitrus; } protected hiFrase(): string { return "Hi! I\'m an aplle and my name is " + this.name + " and I'm " + (this.isCitrus ? "" : " not ") + "citrus"; } public sayHi() { alert(this.hiFrase()) } }
If you want the method to be truly private, do not declare it in the base class.
abstract class Fruit { name: string; constructor (name: string) { this.name = name } } class Apple extends Fruit { isCitrus: boolean; constructor(name: string, isCitrus: boolean) { super(name); this.isCitrus = isCitrus; } private hiFrase(): string { return "Hi! I\'m an aplle and my name is " + this.name + " and I'm " + (this.isCitrus ? "" : " not ") + "citrus"; } public sayHi() { alert(this.hiFrase()) } }
source share