Skip to content
Justice Tech School

Inheritance and Abstract Classes

extends inherits from a class, super calls the parent and override marks replacements. abstract classes cannot be instantiated and may declare abstract methods.

Example
abstract class Animal {
  constructor(protected name: string) {}
  abstract speak(): string;
  intro() { return `${this.name} says ${this.speak()}`; }
}
class Dog extends Animal { speak() { return "Woof"; } }
class Cat extends Animal { speak() { return "Meow"; } }
for (const a of [new Dog("Rex"), new Cat("Tom")]) console.log(a.intro());

Result

Rex says Woof
Tom says Meow

Exercise

Parent class call.

.speak()

Quiz Test

Can you instantiate an abstract class?

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