JS Built-ins
Prototypesadvanced

Prototypes β€” Complex inheritance hierarchies

πŸ“– Usage Example
class A { a() { return 'A'; } }
class B extends A { b() { return 'B'; } }
class C extends B { c() { return 'C'; } }
const obj = new C();
obj.a(); obj.b(); obj.c(); // all work

Deep inheritance chains give the child class access to all ancestor methods.

Multi-Level Class Inheritance

Classes can form deep hierarchies where a class extends another class which itself extends another. The instanceof operator works through the entire chain, and super() needs proper initialization at each level.

Challenge: Create a multi-level class hierarchy with proper initialization and method overriding.

πŸ’‘ Hints (4)
  • β€’ super() calls parent constructor and must pass appropriate arguments
  • β€’ super.method() walks up the chain
  • β€’ instanceof works through entire hierarchy
  • β€’ Each class adds its own layer of functionality