JS Built-ins
Prototypesintermediate

Prototypes β€” Overriding parent methods

πŸ“– Usage Example
class Animal { speak() { return 'generic sound'; } }
class Cat extends Animal { speak() { return 'meow'; } }
new Cat().speak(); // 'meow'

Override a parent method in the child class to change its behavior.

Replacing Parent Methods in Subclass

A subclass can override (redefine) methods from the parent class. When you call the method on a subclass instance, the subclass version is used instead of the parent's.

Challenge: Create a subclass that overrides a parent method with different behavior.

πŸ’‘ Hints (3)
  • β€’ Override by defining the method in the subclass
  • β€’ The subclass version shadows the parent version
  • β€’ Parent method is not affected