typescript
/

TypeScript Abstract Classes

Last Sync: Today

On this page

9
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

typescript

TypeScript Abstract Classes

What is an Abstract Class?

An abstract class is a base class that cannot be instantiated directly and may contain abstract methods that must be implemented by subclasses.

Abstract Class Example

TypeScriptRead-only
1
abstract class Animal {
  abstract makeSound(): void;

  move() {
    console.log('Moving');
  }
}

Extending Abstract Class

TypeScriptRead-only
1
class Dog extends Animal {
  makeSound() {
    console.log('Bark');
  }
}

Cannot Instantiate

TypeScriptRead-only
1
// const a = new Animal(); // Error

Abstract vs Interface

FeatureAbstract ClassInterface
MethodsAbstract + concreteOnly declarations
ImplementationYesNo
InheritanceSingleMultiple

When to Use

  • Shared base functionality
  • Enforcing method implementation
  • OOP design patterns
  • Code reuse with structure

Best Practices

  • Use abstract for base classes
  • Keep abstract classes focused
  • Avoid unnecessary abstraction
  • Combine with inheritance properly

Common Mistakes

  • Trying to instantiate abstract class
  • Not implementing abstract methods
  • Overusing abstraction
  • Confusing with interfaces

Conclusion

Abstract classes provide a structured way to define base behavior while enforcing implementation in derived classes.

Try it yourself

abstract class A { abstract run(): void; }

Test Your Knowledge

Q1
of 3

Abstract class instantiated?

A
Yes
B
No
C
Sometimes
D
Only once
Q2
of 3

Abstract method has?

A
Body
B
No body
C
Return only
D
Variable
Q3
of 3

Keyword?

A
class
B
abstract
C
extends
D
interface

Frequently Asked Questions

What is abstract class?

A class that cannot be instantiated.

Abstract method?

Method without implementation.

Difference from interface?

Abstract can have implementation.

Previous

ts inheritance

Next

ts interfaces vs types

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.