Abstract Class with Abstract Method
Write a TypeScript abstract class Animal with an abstract method makeSound(): string, and a concrete subclass Dog that implements it. Abstract classes cannot be instantiated directly; they serve as base classes that define a shared interface and common behavior.
The abstract keyword in TypeScript marks a class or method as abstract. Abstract methods have no implementation in the base class and must be overridden in concrete subclasses. Abstract classes can also have concrete methods with shared implementations. This is TypeScript's mechanism for achieving the template method pattern.
Abstract classes differ from interfaces in that they can contain implementation code, constructors, and access modifiers. A class can extend only one abstract class but can implement multiple interfaces. Abstract classes are compiled to JavaScript functions with prototype methods, and the abstract enforcement is only at the type level.
Time complexity is O(1) for method dispatch. Space complexity is O(1) for instances. The abstract keyword is enforced at compile time; attempting to instantiate an abstract class produces a TypeScript compiler error.
Edge cases include abstract classes with multiple abstract methods, abstract classes with concrete methods that call abstract methods, and ensuring the subclass properly calls the parent constructor with super().
Example Input & Output
Consistent output
Final check
Dog says Woof!
Stays same
Same result
Algorithm Flow

Solution Approach
Best Answers
abstract class Animal {
abstract makeSound(): string;
describe(): string {
return "This animal says " + this.makeSound();
}
}
class Dog extends Animal {
makeSound(): string {
return "Woof!";
}
}
function solution(): string {
var d = new Dog();
return d.describe();
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
