OOP – Inheritance (extends), online
Six activities your students do on their own devices. See who's finished, and their scores.
OOP – Inheritance (extends) in one minute
What students need to know
extends is exactly the keyword used to set up inheritance. super() runs the parent's setup logic from within the subclass.
extends creates a subclass that gains the parent's properties and methods. JavaScript is case-sensitive, so it must be lowercase 'extends'.
Mistakes students make
- 'class' must be lowercase - a capital C causes an error.
- 'class' is misspelled as 'clas'.
- 'extends' must be lowercase - a capital E causes an error.
- 'extends' is misspelled as 'extend'.
What students will learn in this module
Every question in Module 50
Quick questions
- Does extends let a class inherit from another class?AYesBNo
- Does super() call the parent class's constructor?AYesBNo
- Is 'Extends' with a capital E valid JavaScript syntax?ANoBYes
- Must 'super' be written in lowercase?ANoBYes
- Is 'extend' (without an s) the correct keyword?AYesBNo
Key terms
Students type the meaning of:
extends
Match the pairs
class Dog extends Animal { ... }Match it to what it doessuper(name);Match it to what it doesLets one class inherit properties and methods from anotherMatch it to what it doesCalls the parent class's constructor inside a child classMatch it to what it doesclass Dog Extends Animal { ... }Match it to what it doesSuper(name);Match it to what it doesFill in the blanks
class Dog _______ Animal {Hint: Type the keyword that lets Dog inherit from Animal.
_____(name);
Hint: Type the keyword that calls the parent class's constructor.
class Cat _______ Animal {Hint: Type the keyword that lets Cat inherit from Animal.
constructor(name) { _____(name); }Hint: Type the keyword that calls the parent class's constructor.
class Puppy _______ Dog {Hint: Type the keyword that lets Puppy inherit from Dog.
Spot the error
Question 1
AClass Ant extends Animal {Bconstructor(name) {Csuper(name);D}E}
Question 2
Aclas Bee extends Animal {Bconstructor(name) {Csuper(name);D}E}
Question 3
Alet name = "Rex";Bclass Fox Extends Animal {Cconstructor(name) {Dsuper(name);E}F}
Question 4
Alet name2 = "Tom";Bclass Owl extend Animal {Cconstructor(name) {Dsuper(name);E}F}
Question 5
Aclass Bear extends Animal {Bconstructor(name) {CSuper(name);D}E}
