Answer the question
In order to leave comments, you need to log in
Why is the abstract method spelled wrong?
There is an abstract class which contains an abstract method (without implementation). There is an ordinary class that inherited an abstract class and defined an implementation of the abstract method:
abstract class Figure {
getArea(): void{
console.log("Not Implemented")
}
abstract getColor(): void {}
}
class Rectangle extends Figure{
getColor() {
console.log('is red');
}
}
// const f = new Figure(); // error
const r = new Rectangle();
console.log(r)
r.getArea();
r.getColor();
abstract getColor
with a red line and displays the following error text:Method 'getColor' cannot have an implementation because it is marked abstract.
Answer the question
In order to leave comments, you need to log in
You have an implementation for getColor. take away
abstract class Figure {
getArea(): void{
console.log("Not Implemented")
}
abstract getColor(): void // {} <<<<<<<<<<<<<<
}
class Rectangle extends Figure{
getColor() {
console.log('is red');
}
}
// const f = new Figure(); // error
const r = new Rectangle();
console.log(r)
r.getArea();
r.getColor();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question