Skip to content
Justice Tech School

Abstract Classes

An abstract class cannot be instantiated and may declare methods subclasses must write.

Example
abstract class Shape {
  abstract area(): number;
  describe() { return "area " + this.area(); }
}
class Sq extends Shape { constructor(private s: number) { super(); } area() { return this.s ** 2; } }
console.log(new Sq(3).describe());

Result

area 9

Exercise

Cannot instantiate.

 class A {}

Quiz Test

Can you new an abstract class?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.